Search code examples
pythonlistdata-retrieval

Retrieve a range of values from list


I'm wondering if I have a list of the list like this:

a = [[43,76],[8,3],[22,80],[71,9]]

If I want to retrieve the second value in the last 3 sub-lists, i.e the second value from index 1 to 3 would be like that:

a[1:3][1]:

3
80
9

Solution

  • My 2c:

    [x[1] for x in a[-3:]]
    

    [3, 80, 9]
    

    Demo