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

  • Home
  • SEARCH
  • 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 8611913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:29:39+00:00 2026-06-12T04:29:39+00:00

I have two lists: header = [Name, Age] detail = [Joe, 22, Dave, 43,

  • 0

I have two lists:

header = ["Name", "Age"]
detail = ["Joe", 22, "Dave", 43, "Herb", 32]

And would like to create a list of dictonaries like this:

[{"Name": "Joe", "Age": 22}, {"Name": "Dave", "Age": 32}, {"Name": "Herb", "Age": 32}]

This method zip gets me partially there, but only adds the first set of values to the dictionary:

>>> dict(zip(header, detail))
{'Age': 22, 'Name': 'Joe'}

How can I output as one dictionary for all values in the detail list? I found this answer, but this depends on detail containing nested lists.

  • 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-06-12T04:29:41+00:00Added an answer on June 12, 2026 at 4:29 am

    For such tasks I prefer functional approach.

    Here is a recipe for grouper:

    def grouper(n, iterable, fillvalue=None):
        "Collect data into fixed-length chunks or blocks"
        # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
        args = [iter(iterable)] * n
        return izip_longest(fillvalue=fillvalue, *args)
    

    By using it, we may advance trough detail by groups of 2:

    >>> groups = grouper(len(header),detail)
    >>> list(groups)
    [('Joe', 22), ('Dave', 43), ('Herb', 32)]
    

    And then we can use this iterator to create dictionaries as you need:

    >>> [dict(zip(header,group)) for group in groups]
    [{'Age': 22, 'Name': 'Joe'}, {'Age': 43, 'Name': 'Dave'}, {'Age': 32, 'Name': 'Herb'}]
    

    To clarify, zip(header,group) gives this:

    >>> zip(["Name", "Age"],('Joe', 22))
    [('Name', 'Joe'), ('Age', 22)]
    

    And summoning dict constructor gives this:

    >>> dict([('Name', 'Joe'), ('Age', 22)])
    {'Age': 22, 'Name': 'Joe'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Lists, they look like this <List> ads [0] Headline = Sony
I have two lists as List <BillDetails>= new List<BillDetails>(); List<Header>=new List<Header>(); Public class Billdetails
I have two lists. Ex: List<string> expected = new List<string>(); expected.Add( a ); expected.Add(
I have two lists. They are sortable but not connected (elements of list one
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have two lists: listA: [[Name: mr good, note: good,rating:9], [Name: mr bad, note:
I have two tables like these: USER id name MESSAGE id sender_id receiver_id As
I have a list of custom objects: say Fruits with two string properties Name
I have two Lists of dictionaries. Both are not not null. How to merge

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.