Code :
lst = [10, 25, 4, 12, 3, 8]
sorted(lst)
print(lst)
Solution and Explanation :
The above code sorts the list lst using the sorted() function, but it doesn't modify the original list. The sorted() function returns a new sorted list without changing the original list. If you want to sort the original list in-place, you can use the sort() method of the list:
lst = [10, 25, 4, 12, 3, 8]
lst.sort()
print(lst)
This will modify the original list lst and print the sorted result. If you want to keep the original list unchanged and create a new sorted list, you can use sorted() and assign it to a new variable:
lst = [10, 25, 4, 12, 3, 8]
sorted_lst = sorted(lst)
print(sorted_lst)
print(lst)
In this case, sorted_lst will contain the sorted version of the original list, and lst will remain unchanged.
0 Comments:
Post a Comment