[Tutor] Difference between for i in range(len(object)) and for i
alan.gauld at freenet.co.uk
Fri Dec 10 01:26:05 CET 2004
> Here is my code:
> >>> spot_cor=
> >>> for m in cor:
> ... cols = split(cor,'\t')
You are splitting the list not the item
cols = split(m, '\t')
Better to use a meaningful name too:
for line in cor:
would probably have made the mistake more obvious.
> However, when I tried that using some data, as
> demonstrated above, I get error because append method
No its the spil method that doesn't exist and that
was because you were passing the list instead of
Once you get used to the "foreach" semantics of "for"
it really is a better way of working than messing
around with indexes.
More information about the Tutor