[Tutor] walking a list

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 11 Dec 2001 23:39:45 -0800 (PST)


> 
> Sokay, now try to walk it in a for loop:
> 
> for i in members:
>       print members[1]
> 
> Gets this error:
> 
>       
> Traceback (most recent call last):
>   File "<pyshell#119>", line 2, in ?
>     print members[i]
> TypeError: sequence index must be integer
>>>>|
> 
> 
> ok, how do I get it to walk through a loop, performing a block of code
> for each item in the list?
> 

>>> l = ['s', 't', 'r']
>>> for i in l:
...     print type(i)
... 
<type 'string'>
<type 'string'>
<type 'string'>

hope this makes shows the error of your ways.