5. Lists and tuples#

Sometimes we do not have only a single value to deal with but a collection of values. We cannot hard code a single variable for each of the values as there are situations when we do not even know the number of values we would have to deal with. Lists and tuples are helpful in these situations because they allow us to enclose multiple values in the same variable. In the following chapter, we are going to explore these two data types.

Chapter Summary

  • Lists:

    • number of elements in a list

    • accessing elements of a list

    • add/remove elements to/from a list

    • list comprehensions

    • sort lists

    • search lists

  • Tuples:

    • number of elements in a tuple

    • accessing elements of a tuple

    • add/remove elements to/from a tuple

    • search lists

    • counting elements in a tuple

  • Unpacking variables

  • zip() function

  • del statement

  • Passing lists/tuples to functions

  • 2D lists

  • Functional-style programming