0
How to sort a list in alphabetical order in python
9 Respuestas
+ 3
list.sort()
+ 3
Granger a set is not an ordered list. Converting a list to a set will remove any duplicate values and return an unordered collection.
https://docs.python.org/3.8/library/stdtypes.html#set-types-set-frozenset
Amit Kumar You can use the list.sort() method as Julia Shabanova has stated to sort the original list itself in place in lexicographical order, or use the lst = sorted(list) function to return a copy of the lexicographically sorted list.
Note that uppercase letters have a lower value and will be ordered prior to lowercase.
https://docs.python.org/3/tutorial/datastructures.html
https://docs.python.org/3/library/functions.html#sorted
+ 3
Granger You stated "Set is a sorted list.", this is false. That is all I was commenting on concerning your post, but you're welcome, I guess.
+ 3
Granger That is true, but the 2 statements do not correlate. Just because there are no duplicates in the original list does not mean that converting to a set (using set(list)) will give you a sorted list. In fact after using set() you won't have a list at all, but rather a set object which the order of its elements will be arbitrary.
I'm simply trying to clarify for the OP, so as to give factual information that won't confuse them or anyone who reads your post any further, if they don't understand what a set is in the first place.
0
Use the sort()method
[whatever].sort ()
- 1
Thank u