I apologize I am not sure of the terminology of Python.
I have a Class called "Word" and what it does is count and store all the words in a given text file as a tuple I.e.
self.listName = [('world', 2), ('hello', 3), ('stack', 1), ('overflow', 2)]
where the item of index 0 is the word and index 1 is the occurrences. This is stored within the the class "word". is there any way I can use the
listName.sort()
or
sorted(listName, key=lambda Word: Word[0])
to give me the following list:
self.listName = [('hello', 3), ('overflow', 2), ('stack', 1), ('world', 2)]
I want to try to use this rather than attempting to create a new sorting function (which I believe I can do, but I have not been successful)?
I think I should also mention that the List and the Word classes are in different classes (if that makes a difference).
thanks in advance!