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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:50:07+00:00 2026-05-29T07:50:07+00:00

I have a dictionary of lists, where the lists represent columns. All the lists

  • 0

I have a dictionary of lists, where the lists represent columns. All the lists are the same length and the number of lists is variable. I want to convert the lists of columns into lists of rows. It doesn’t have to end in a dictionary a matrix is perfect; however, I can’t use numpy.

For example: The setup looks something like this

>>> A = [ 1 ,  2 ,  3 ,  4 ,  5 ,  6]
>>> B = ["A", "B", "C", "D", "E", "F"]
>>> C = ["J", "K", "L", "M", "N", "O"]
>>> d = {"One": A, "Two": B, "Three": C}

do magic here and get the following

[(1, 'A', 'J'), (2, 'B', 'K'), (3, 'C', 'L'), (4, 'D', 'M'), (5, 'E', 'N'), (6, 'F', 'O')]

Notice the first element in the cols are now in a row. Now I can get this by doing

>>> zip(d["One"], d["Two"], d["Three"])

but this would only work if the number of dictionary entries was constant. How can I do this if the number of dictionary entries was variable? Hope I’m clear.

  • 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-29T07:50:08+00:00Added an answer on May 29, 2026 at 7:50 am

    Check out the documentation for Unpacking Argument Lists. By putting a * in front of an iterable that is an argument to a function, the function will be called with the elements from that iterable as its arguments. For example zip(*['ab', 'cd', 'ef']) would become zip('ab', 'cd', 'ef').

    Using this method you can generate your zipped list of an arbitrarily sized dictionary, but note that because dictionaries are unordered you will need to provide a separate list to use as an order for the resulting column groups, for example:

    >>> A = [ 1 ,  2 ,  3 ,  4 ,  5 ,  6]
    >>> B = ["A", "B", "C", "D", "E", "F"]
    >>> C = ["J", "K", "L", "M", "N", "O"]
    >>> d = {"One": A, "Two": B, "Three": C}
    >>> order = ["One", "Two", "Three"]
    >>> zip(*[d[k] for k in order])
    [(1, 'A', 'J'), (2, 'B', 'K'), (3, 'C', 'L'), (4, 'D', 'M'), (5, 'E', 'N'), (6, 'F', 'O')]
    

    If the column order does not matter, you can use Sven’s solution which is very concise but the tuple order will be arbitrary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 lists, both of which contain same number of dictionaries. Each dictionary
Beginner question: I have a dictionary where the values are lists of (a variable
I want to have a Dictionary that maps strings to generic lists of varying
I have a dictionary that has keys associated with lists. mydict = {'fruits': ['banana',
I'm trying to map a Dictionary containing Lists. I have the following set of
I have a Dictionary<string, List<Order>> and I want to have the list of keys
I have a dictionary (index2) of 3-item lists, organized by key from 0-150 or
I have a Dictionary of Classes where the classes hold attributes that are lists
I have a dictionary in C# like Dictionary<Person, int> and I want to sort
I have a dictionary of numbers to lists of numbers like: a = {

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.