I am using a class instance which returns a string.
I am calling twice this instance and collecting returned values into a list. Then am trying to use .sort() to sort these two strings. However, when I do so it throws an error saying that the type is (Nonetype - considers it as object).
I did check with type(element of a list) and it returned type "string". I have no clue what's going on. Basically in idle it says that I have strings in a list.. but when running it throws an error saying that the NoneType (list of these strings) is not iterable.
here is an example:
list_of_strings = [class_method(args), class_method(another_args)] ## this instance returns string
print type(list_of_strings[0]) #prints type 'str'
ERROR:
list_sorted = list(list_of_strings.sort())
TypeError: 'NoneType' object is not iterable
Thanks a lot!
George
From the python documentation:
7.
Thesort()
andreverse()
methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they operate by side effect, they don’t return the sorted or reversed list.
Use sorted()
:
list_sorted = list(sorted(list_of_strings))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With