[Tutor] List exercise
Anwar.Lorenzo@gmx.net
Anwar.Lorenzo@gmx.net
Fri Feb 7 07:15:02 2003
Hi
I'm trying to solve the exercise:
As an exercise, write a loop that traverses the previous list
(['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]) and
prints the length of each element. What happens if you send an
integer to len? (exercise from 8.3)
from the ebook How To Think Like A Computer Scientist: Learning with
Python.
I've coded a function to solve this but it doesn't seem to work. IDLE
just hangs when I execute this function.
Here's my solution:
def exerSize():
exer = ['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]
i = 0
while i < len(exer):
len(exer[i])
i = i + 1
Thanks in advance!
-Anwar