Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3790468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:19:09+00:00 2026-05-19T12:19:09+00:00

I have three collection.deques and what I need to do is to iterate over

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:19:10+00:00Added an answer on May 19, 2026 at 12:19 pm

    Depending on what order you want to process the items:

    import itertools
    
    for items in itertools.izip(deque1, deque2, deque3):
        for item in items:
            some_action(item)
    
    for item in itertools.chain(deque1, deque2, deque3):
        some_action(item)
    

    I’d recommend doing this to avoid hard-coding the actual deques or number of deques:

    deques = [deque1, deque2, deque3]
    for item in itertools.chain(*deques):
        some_action(item)
    

    To demonstrate the difference in order of the above methods:

    >>> a = range(5)
    >>> b = range(5)
    >>> c = range(5)
    >>> d = [a, b, c]
    >>>
    >>> for items in itertools.izip(*d):
    ...     for item in items:
    ...         print item,
    ...
    0 0 0 1 1 1 2 2 2 3 3 3 4 4 4
    >>>
    >>> for item in itertools.chain(*d):
    ...     print item,
    ...
    0 1 2 3 4 0 1 2 3 4 0 1 2 3 4
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three threads that need access to a collection and I use
I have a collection of permissions. Each permission would have three properties: Id, Name,
In my application, I have three collection objects which store data. The data which
I have a dataset consisting of a large collection of points in three dimensional
I have three different List collections. How can I show them in one ListBox
I have three entities: User , Team , and TeamInvite . Each User has
I have a collection of objects we'll call People each comprised of Name, ID
I have three classes a) Parent - Which contains some properties, an Item collection
I have three cells in different rows in a table having same name.e.g. <td
Here is my case: I have a MongoDB collection in Node.Js. Let's say three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.