[NEWBIE] Priority Queue in Python

Terry Reedy tjreedy at udel.edu
Sat Feb 3 19:36:36 EST 2001


> for i in list:
>     print i, "is the", list.index(i), "element"
>
> The index() call takes too long, I wish there was like a hidden
> variable so I could say it like this.  Is there?

Yes, tidbit is O(len(list))**2

>
> for i in list:
>     print i, "is the", __loopindex__, "element"

Since list() is a builtin function, best not to use as a variable name.
Common idiom is as follows:

for i in range(len(listx)):
    print listx[i], 'is the', i, 'th element

Exposing the internal loopindex has been discused, but never agreement
reached.





More information about the Python-list mailing list