0
What is difference between .sort() and .sorted() in python?
4 odpowiedzi
+ 3
The sort() is used only on lists and it modifies the original list while the sorted() can be used for both strings and lists, instead of modifying the original list it returns a new list
+ 4
Just to complete the statement from Justus: sorted() is not limited to list and string, it does also work with tuple and with set as argument.
+ 2
Check this
a =list('4568239')
print(sorted(a))
print(a)
a.sort()
print(a)
0
Works fine.
Which?