0
the method "sort()"
What is the function of sort() ?
2 Réponses
+ 6
The difference of sort() and sorted() in short words:
sort() - using sort() will change (sort) the passed list to the function inline, that means that the original list will be sorted. sort() only works for lists.
sorted() - using sorted() will take any iterable (list, tuple, string, dict), not only list, and will return a new sorted iterable. The initial iterable keeps unchanged.
+ 1
If you have a list it helps to sort the list.
Simple example would be
list_1=[2,7,9,4,6,1]
list_1.sort()
print(list_1)
Output will be [1,2,4,6,7,9]..