position in a for loop?
castor at snafu.de
Wed Dec 31 16:16:43 CET 2003
you may want to have a look @
where it is said that 'the interpreter creates a secret
name that only exists while the list is being built.
That name is (usually) "_", and it refers to the bound
method "append" of the list.'. for your specific problem,
the enumerate() solution is probably all that you need;
for other cases (such as checking whether a certain value
is already a member of the list), this solution may come
in handy. for example, in order to get a non-repetitive
string with all the characters found in a given text, you
for x in 'my words are repetitive'
if x not in locals()['_'].__self__ ] )
hope that helps,
More information about the Python-list