Lists in Python
Lists can be used to store multiple elements of the same or different datatypes. Lists are variable length data structure. If you are new you will be using this a lot and if you have been using it, let me share some more tips and tricks.
|
|
abc.append()
Adds at the end of the list. Time Complexity O(1)
|
|
Similar methods for adding to a list are .insert(index, elem)
& .extend(another_list)
.insert(index, elem)
inserts the element at the given index, shifting elements to the right. Time Complexity O(n).
abc.extend(def)
adds the elements in list def
to the end of the list abc
. Time Complexity O(k), where k is the length of list def
|
|