position in a for loop?

From: EP (EP_at_zomething.com)
Date: 12/31/03


Date: Tue, 30 Dec 2003 21:30:57 -0800
To: python-list@python.org

In fear of bringing down the quality of the list, I nevertheless will ask:

How I can tell where I am in a for loop?

I think I am working way too hard to try to determine this - there is
probably a very simple way to know?

Spam_locations=[]
list=['linguine','Spam', 'clams', 'Spam', 'steak', 'onions', 'apples', 'Spam']
for food in list:
         if food='Spam':
         Spam_location.append(## position in list ##) ## but how do I
back reference the position in the for loop?

I am hoping to get:

>>> Print Spam_locations
[1,3,7]

I was thinking the back reference might be something like:
Spam_location.append(list.__iter__())
But that gives me <listiterator object at 0x00DBE3B0> not a value (position)...

I promise to be smarter next year... any help?

EP



Relevant Pages

  • Re: StackOverflow Exception in JNI
    ... > I have a loop written in C/JNI which calls back a Java object (which ... temporary objects in your native method and then return a valid ... reference without thinking too much about these issues. ...
    (comp.lang.java.programmer)
  • Re: Looping-related Memory Leak
    ... memory leak / balloon for reasons I cannot figure out. ... end of the loop. ... reference count never reaches zero, and they remain alive until the ... the generational collector doesn't break cycles that involve ...
    (comp.lang.python)
  • Re: dynamic form validation / multiple forms
    ... for diagnosing the problems that produce errors on the browser. ... part is redundant as soon as you are passing the reference to the form ... of the form element but then using that name to look-up ... global variables a loop counters is particularly problematic as it ...
    (comp.lang.javascript)
  • Re: Holding Returned Data in Arrays
    ... According to the docs foreach uses the IEnumerable/IEnumerator interface ... so it will have to store the reference ... > Or I could hold that output in an array and loop through that collection: ... I always thought GetFiles() would be called once and then the output ...
    (microsoft.public.dotnet.framework.clr)
  • Re: general performance question
    ... first Object is eligible for garbage collection. ... For a loop, the value set in the last iteration also leaks the ... How can it if the reference is created in the block? ... The method's stack frame isn't collected until the method exits; it has no notion of block scope. ...
    (comp.lang.java.programmer)