# python – Access item in a list of lists

## python – Access item in a list of lists

You can access the elements in a list-of-lists by first specifying which list youre interested in and then specifying which element of that list you want. For example, `17` is element `2` in list `0`, which is `list1`:

``````>>> list1 = [[10,13,17],[3,5,1],[13,11,12]]
>>> list1
17
``````

``````50 - list1 + list1 - list1
``````

You can use `itertools.cycle`:

``````>>> from itertools import cycle
>>> lis = [[10,13,17],[3,5,1],[13,11,12]]
>>> cyc = cycle((-1, 1))
>>> 50 + sum(x*next(cyc) for x in lis)   # lis is [10,13,17]
36
``````

Here the generator expression inside `sum` would return something like this:

``````>>> cyc = cycle((-1, 1))
>>> [x*next(cyc) for x in lis]
[-10, 13, -17]
``````

You can also use `zip` here:

``````>>> cyc = cycle((-1, 1))
>>> [x*y for x, y  in zip(lis, cyc)]
[-10, 13, -17]
``````

#### python – Access item in a list of lists

``````List1 = [[10,-13,17],[3,5,1],[13,11,12]]

num = 50
for i in List1:num -= i
print num
``````