[Tutor] Final review

Matt Harris matt at hazza.net
Thu May 1 11:35:51 CEST 2014


> The ouput for below is 2 when it seems like there should be 3 lists located inside x.  Is it [10,20] that is not consider inside of x?    Any tips on how to tell how to spot them more clearly?
>
> x = ['a', [2.0, 5, [10, 20]]]
> print len(x)


Hey Scott

Here, it looks like x is a list containing 'a' and [2.0, 5, [10, 20]],
hence why the len(x) gives 2.

len(x[1]) gives you 3 ( [2.0, 5, [10, 20]] )
len(x[1][2]) gives you 2 (  [10, 20] )

Matt


More information about the Tutor mailing list