List as FIFO in for loop

malkarouri malkarouri at gmail.com
Sat Mar 8 17:37:11 EST 2008


On Mar 8, 6:24 pm, rockingred <willsteve2... at yahoo.ca> wrote:
> I think it's a bad practice to get into.  Did you intend to do the
> "process" step again over the added variables?  If not I would set a
> new variable, based on your awful naming convention, let's call it z.
> Then use z.append(y) within the for loop and after you are out of your
> for loop, q.append(z).

Thanks, rockingred, for the advice. I hope that you didn't assume that
I was a newbie, even if my question looks so. What I was trying to do
is write some Python code which I need to optimize as much as
possible. I am using Cython (Pyrex) and would probably end up
rewriting my whole module in C at one point, but it is really hard to
beat Python data structures at their home turf. So meanwhile, I am
making use of dubious optimizations - on my own responsibility. There
have been a lot of these along the years - like using variables
leaking from list expressions (not anymore). Think of it as a goto.
Yes, I intend to do the process step again over the added variables.
The suggested deque is probably the best, though I need the speed
here.
What are the variable naming you would suggest, for a throwaway -
probably anonymized for the same of publishing on the web - code?

Cheers,

Muhammad Alkarouri



More information about the Python-list mailing list