+ 2

What is the code out put Sp=[[4,1],[5,2],[6,3],[7,4]] Print(sp[1][1][0])

kindly explain how to go about this

19th Apr 2017, 6:05 PM
Mevin Ngugi
Mevin Ngugi - avatar
7 Answers
+ 3
sp=[[[4,1],[5,2]],[[6,3],[7,4]]] This should do the trick if you want 7.
19th Apr 2017, 7:33 PM
Tob
Tob - avatar
+ 2
That will just give you an error. Either add some parentheses or remove [0].
19th Apr 2017, 6:54 PM
Tob
Tob - avatar
+ 1
It will output an error, coz that's not how you handle a list... If you want, you might be confusing this with print(sp[1:1:0]) Which is the correct way to handle a list
19th Apr 2017, 6:39 PM
matan
+ 1
@mevin there should be no 3rd argument, in that case. What you are doing is a "list of lists". The first argument is the index of the list you chose, the second is the index of the inner list. There is no need for a third argument.
19th Apr 2017, 7:04 PM
matan
0
actually this is a stacked list. Nothing to do with slicing a list. i know if you run the code with print(sp[1][1]) it will print out 2. so my question is what does the 3rd argument [0] mean
19th Apr 2017, 6:49 PM
Mevin Ngugi
Mevin Ngugi - avatar
0
@tobi the answer according to solo learn is 7 where do I add the parenthesis
19th Apr 2017, 7:20 PM
Mevin Ngugi
Mevin Ngugi - avatar
0
@tobi thank you very much... just reported the question as a wrong answer. I appreciate your time.
19th Apr 2017, 7:50 PM
Mevin Ngugi
Mevin Ngugi - avatar