Lists
I LOVE DOING THIS :)
A List
is a collection of items that are ordered and changeable. Lists are written with square brackets, and the items are separated by commas hence they are Heterogeneous / Dynamic
You can also add new items to a list by using the append()
method or by inserting them at a specific position with the insert()
method
You can remove items from a list by using the remove()
method or by deleting them at a specific position with the del
statement
If you have an unsorted list [4,3,5,1]
, you can sort it using the sort
method
If you have a list [1, 3, 4, 5]
and you need to reverse it, you can call the reverse
method
Similar to the sort method, you can also use the sorted function which also sorts the list. The difference is that it returns the sorted list, while the sort method sorts the list in place. So this function can be used when you want to preserve the original list as well.
Last updated