Skip to main content

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 list
  • clear() - Removes all items from list
  • copy() - Returns a shallow copy of the list
  • count() - Returns the count of the elements of the list
  • extend() - Adds iterable elements to end of list
  • index() - Returns the index of the element of the list
  • insert() - Inserts an element into the list
  • pop() - Removes and returns the element at the given index
  • remove() - Removes the item from the list
  • reverse() - Reverses the list
  • sort() - Sorts the list

Used on list:

  • len() - Returns size of list
  • min() - Returns smallest element in list
  • max() - 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)

References