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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:34:30+00:00 2026-06-17T18:34:30+00:00

I have the following data structure: {‘one’:[‘a’,’b’,’c’],’two’:[‘q’,’w’,’e’],’three’:[‘t’,’u’,’y’],…} . So, the dictionary has variant count

  • 0

I have the following data structure: {'one':['a','b','c'],'two':['q','w','e'],'three':['t','u','y'],...}. So, the dictionary has variant count of keys. Each array, picked by dict’s key has similar length. How I can convert this structure to following: [{'one':'a','two':'q','three':'t'},{'one':'b','two':'w','three':'y'},...]?

I think I should use itertools.izip(), but how i can apply it with not predefined count of args? Maybe something like this: itertools.izip([data[l] for l in data.keys()])?

TIA!

  • 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-17T18:34:31+00:00Added an answer on June 17, 2026 at 6:34 pm

    Your assessment in using izip is correct but the way of using it is not quite right

    You first need to

    • get the items as a list of tuples (key, value), (using iteritems() method if using Py2.x or items() if using Py3.x)
    • create a scalar product of key and value
    • flatten the list (using itertools.chain)
    • zip it (using itertools.izip)
    • and then create a dict of each element

    Here is the sample code

    >>> from pprint import PrettyPrinter
    >>> pp = PrettyPrinter(indent = 4)
    >>> pp.pprint(map(dict, izip(*chain((product([k], v) for k, v in data.items())))))
    [   {   'one': 'a', 'three': 't', 'two': 'q'},
        {   'one': 'b', 'three': 'u', 'two': 'w'},
        {   'one': 'c', 'three': 'y', 'two': 'e'}]
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data structure: One ModelA has a nested collection of ModelBs.
I have the following Python 2.7 dictionary data structure (I do not control source
Based on couple of Api Calls I have constructed the following data structure (Dictionary).
Suppose I have the following data structure: a Customer entity that has a collection
I have the following data structure in Ruby (a hash where keys are strings,
I have following data structure (simplified): A giant list of the class TestClass public
I have the following data structure: P_ID EVSSMIN EVSSMAX TDMIN TDMAX WARD SYRINGE_ID COMBINE_WITH
I have the following data structure (an atomic vector?) output from daply in plyr
I have the following JavaScript data structure. a[] is an array with text strings
I have the following data set structure: date time_in_hours price Sep 03 08 9.76

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.