-1
a=["four", "score", "and", "seven", "years"][[0,2,3][1]]

print(a)

output is : and

What is the main logic of this expression ?

0

2 Answers 2

3

You need to read such expressions from the inside out. Let's start with the original:

a = ["four", "score", "and", "seven", "years"][[0,2,3][1]]

[0,2,3] is a list, so you can access its elements with the [] operator. Since lists are zero-based, index 1 is the second item, which is 2:

a = ["four", "score", "and", "seven", "years"][2]

Here, again, we're accessing a list element by its index. 2 refers to the third element, which is "and".

Sign up to request clarification or add additional context in comments.

Comments

0

[0,2,3][1] gives 2 which goes into ["four", "score", "and", "seven", "years"][2] which in turn returns and.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.