8.2. Nested List of Tuples

  • Iterable is an object

  • Iterable element is an object too

  • Therefore an element of a Iterable could be another Iterable

  • There is no limit how nested it could be

Examples:

>>> users = [
...     ('Alice', 'Apricot'),
...     ('Bob', 'Blackthorn'),
...     ('Carol', 'Corn'),
... ]

8.2.1. Format

  • Readability differs depending on whitespaces

>>> data = [
...     ('Alice', 'Apricot'),
...     ('Bob', 'Blackthorn'),
...     ('Carol', 'Corn'),
... ]
>>> data = [
...     ('Alice', 'Apricot'),
...     ('Bob', 'Blackthorn'),
...     ('Carol', 'Corn')]
>>> data = [('Alice', 'Apricot'),
...         ('Bob', 'Blackthorn'),
...         ('Carol', 'Corn')]

8.2.2. Length

>>> data = [
...     ('Alice', 'Apricot'),
...     ('Bob', 'Blackthorn'),
...     ('Carol', 'Corn'),
... ]
>>> len(data)
3
>>> len(data[0])
2
>>> len(data[0][0])
5

8.2.3. Assignments