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 7681923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:27:08+00:00 2026-05-31T18:27:08+00:00

I have three lists of lists, and I’m trying to write a generator function

  • 0

I have three lists of lists, and I’m trying to write a generator function to help me package up values in the same index.

So my lists:

list1 = [[1, 2, 3], [2, 3, 4],...]
list2 = [[4, 5, 6], [5, 6, 7],...]
list3 = [[8, 9, 10], [9, 10, 11],...]

My desired output:

result1 = [[1, 4, 8], [2, 5, 9],...]
result2 = [[2, 5, 9], [3, 6, 10],...]
result3 = [[3, 6, 10], [4, 7, 11],...]

My attempt:

def bundle(x, y, z, index):
    for row in x, y, z:
        for item in row[index]:
            yield list(item)

I keep getting float is not iterable errors. If i modify it slightly:

def bundle(x, y, z, index):
    for row in x, y, z:
        for item in row:
            yield item[index]

I get the values I want as one large sequence, but I would prefer to keep them grouped in a nested style.

  • 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-31T18:27:09+00:00Added an answer on May 31, 2026 at 6:27 pm

    If you’re dealing with large lists, a custom, fully lazy approach would be the following:

    import itertools as it
    
    def bundle(lists, index):
      return ([b[index] for b in blocks] for blocks in it.izip(*lists))
    
    print list(bundle([[[1, 2, 3],  [2, 3, 4]], 
                       [[4, 5, 6],  [5, 6, 7]], 
                       [[8, 9, 10], [9, 10, 11]]], 
                      0))
    # => [[1, 4, 8], [2, 5, 9]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have three lists: list1 = a, c, d, r, t list2 =
I have three lists, BeforeList, AfterList and FinalList BeforeList has the following values ID
I have 3 functions which generate three different lists. I am trying to generate
I have three lists that I want to convert into one list. When I
I have three unordered lists that have been created as Scriptaculous Sortables so that
So I currently have three unordered lists in my header. This is a single-page
I'm completely stumped on this one. I have three different lists that need to
Let's say I have the three following lists A1 A2 A3 B1 B2 C1
I have three cascaded drop down lists. ddlIllnessType, ddlIllnessSubType and ddlInfectiousAgent Initially, only ddlIllnessType
I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list

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.