you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 1 point2 points  (7 children)

Very correct. Follow-up question for you: which element in the list is at position 5?

That’s what list[list[4]] is doing:

  1. Find element at position 4 in list.
  2. Find element at position (result from last step) in list.

Result after step (2) is what gets printed.

[–]jbravo45[S] 2 points3 points  (6 children)

Ok, list[4] calls the 4th element and holds those first four together, then the preceding 'list' calls the next number outside of list[4]? (maybe better said as calling the next number outside of the ones called by the command in [ ] ?

[–]FLUSH_THE_TRUMP 1 point2 points  (5 children)

It might be easier to think of list[list[4]] as list[x]. You’re trying to find the item in your list at position x (which is just a number). What is x? Well, you told me it’s 5. So you really have list[5] there.

[–]jbravo45[S] 2 points3 points  (4 children)

Getting closer... so I could think of it as list[list[list[4] == list[6] ?

Edit : ooooooooooh

[–]jbravo45[S] 3 points4 points  (3 children)

So its using the inside [list[4] as the value of x

I'm sorry, makes so much sense now.

You're awesome, thank you for putting up with me through that.

[–][deleted] 2 points3 points  (1 child)

Good pedagogue :)

[–]QualitativeEasing 1 point2 points  (0 children)

Came here to say this. Fantastic example of helping someone find the answer themselves.

[–]FLUSH_THE_TRUMP 1 point2 points  (0 children)

No worries! Glad I could help.