['table lights', 'table', 'scanner', 'printer', 'fan']
>>>
Coupled with the sort() method is the sorted() function. While the sort()
method
permanently reorders a list, the sorted()
function makes temporary
changes.
officeitems = ['printer', 'scanner', 'fan', 'table', 'table lights']
print(officeitems)
print(sorted(officeitems))
print(officeitems)
= RESTART: C:/Users/saifia computers/Desktop/sample.py
['printer', 'scanner', 'fan', 'table', 'table lights']
['fan', 'printer', 'scanner', 'table', 'table lights']
['printer', 'scanner', 'fan', 'table', 'table lights']
>>>
You can see that the sorted() function temporarily
changed the order of the
list. When I printed the list without the sorted() function, it comes back into
its original order.
Do'stlaringiz bilan baham: