Could somebody explain to me why the code I used to complete this exercise doesn't work.
And how do you send an integer to len?

Thanks

Ben

==================================


As an exercise, write a loop that traverses a list and prints the length of each element. What happens if you send an integer to len?

>>> foo = ['spam!', 1, ['brie', 'cheddar', 'swiss'], [1, 2, 3]]
>>> i = 0
>>> while i < len(foo):
                 print len(foo[i])
                 i = i+1

    
5

Traceback (most recent call last):
  File "<pyshell#28>", line 2, in -toplevel-
    print len(foo[i])
TypeError: len() of unsized object
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to