I have three collection.deques and what I need to do is to iterate over each of them and perform the same action:
for obj in deque1:
some_action(obj)
for obj in deque2:
some_action(obj)
for obj in deque3:
some_action(obj)
I'm looking for some function XXX which would ideally allow me to write:
for obj in XXX(deque1, deque2, deque3):
some_action(obj)
The important thing here is that XXX have to be efficient enough - without making copy or silently using range(), etc. I was expecting to find it in built-in functions, but I found nothing similar to it so far.
Is there such thing already in Python or I have to write a function for that by myself?
Call me crazy, but why is using itertools thought to be necessary? What's wrong with:
Even crazier: you probably are going to use this once. Why not just do:
What's going on there is immediately obvious without having to look at the code/docs for the long-name function or having to look up the docs for itertools.something()
If I understand your question correctly, then you can use
map
with the first argument set to None, and all the other arguments as your lists to iterate over.E.g (from an iPython prompt, but you get the idea):
How about zip?