Lists
Concepts
Mapping
Takes a whole iterable, and returns a new iterable after applying a transformation function to it.
Filtering
Takes a whole iterable, and returns a subset of that iterable
Reducing
Takes a whole iterable, and returns a single cumulative value. E.g. Sum
Methods
append()- Adds a single element to the end of the listclear()- Removes all items from listcopy()- Returns a shallow copy of the listcount()- Returns the count of the elements of the listextend()- Adds iterable elements to end of listindex()- Returns the index of the element of the listinsert()- Inserts an element into the listpop()- Removes and returns the element at the given indexremove()- Removes the item from the listreverse()- Reverses the listsort()- Sorts the list
Used on list:
len()- Returns size of listmin()- Returns smallest element in listmax()- Returns largest element in list
Creating a List
# a list of three elements
ages = [19, 26, 29]
print(ages)
# Output: [19, 26, 29]
Iterating on a List
fruits = ['apple', 'banana', 'orange']
# iterate through the list
for fruit in fruits:
print(fruit)