Getting a specific thing out of a list

I am very, very confused, when I do

It outputs [[[1, 12], 1.0, 3, '39', 2]]

But if I do self.breach_strings.append(state["events"]["breach"][0][0])
It outputs [1, 12]

Why does it skip like that, and how do I get the one in the middle?

This is just how nested indexing works. Your first call returned an entire list. To make things more clear, let’s give it a name.

first_breach = state["events"]["breach"][0]

Now first_breach is that list that got printed: [ [1,12], 1.0, 3, β€˜39’, 2 ]
This list has 5 things in it, at indexes 0, 1, 2, 3, and 4.

So first_breach[0] will be equal to [1,12].

You may want to read some Python websites about how each data structure works:

All of chapter 5 here:

And also just google around for third-party info articles like this:

1 Like