+ 1

Why not the output is 2?

a = [[[[8,9,0]],8]] print (len(a))

18th Sep 2019, 1:52 PM
Navneet
Navneet - avatar
6 Answers
+ 4
Because Array length is 1 Explained here.... Consider first and last Square bracket, only one element is placed. Because you have used another square Bracket at 2nd last position.
18th Sep 2019, 2:09 PM
Shubham Sharma
Shubham Sharma - avatar
+ 3
Because you are using an array inside another . So it gives length of outer array that is 1. And a[0]=[[[8,9,0]],8]
20th Sep 2019, 5:07 AM
Rajpal Mahich
Rajpal Mahich - avatar
+ 1
~ swim ~ i swear that you 24/7 in this app
18th Sep 2019, 2:44 PM
KfirWe
KfirWe - avatar
+ 1
This is a 4 dimensional array. [ [ [ [8, 9, 0] ], 8] ] When you check length: len([ [ [ [8, 9, 0] ], 8] ]) It only wants to know the length of the outermost list, it does not care what is in innermost lists, we can mark them with ..., because their content doesn't affect the list length: [ [...] ] [ [...] ] is a list with just 1 item: [...] Thus len([ [ [ [8, 9, 0] ], 8] ]) returned 1.
18th Sep 2019, 4:36 PM
Seb TheS
Seb TheS - avatar