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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:03:20+00:00 2026-06-05T17:03:20+00:00

How to create and append dictionary at the same time? def buildList(theDict): array=[] for

  • 0

How to create and append dictionary at the same time?

def buildList(theDict):
    array=[]
    for a,b in theDict.iteritems():
        array.append([a,b])

    return array
print buildList({"a": 1,"b": 2,"c": 3})

This prints out a list of lists. I want to print out a list of dictionaries without creating any new variables.

  • 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-05T17:03:22+00:00Added an answer on June 5, 2026 at 5:03 pm

    If I understand correctly what you want, this code should work.

    def list_of_dicts(d):
        return [{key:value} for key, value in d.iteritems()]
    
    print list_of_dicts({"a": 1,"b": 2,"c": 3})
    

    list_of_dicts() uses a list comprehension, which creates a new dict with a single entry for each key/value pair in the passed-in dictionary.

    Do you see how you could use a list comprehension to re-write your example, and return a list of lists? It would just require changing three characters in the above.

    P.S. I used PEP 8 names (lower_case rather than camelCase).

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

Sidebar

Related Questions

I am trying to create a Python dictionary from a stored list. This first
I'm trying using a TAdoTable component, On form Create I call .Append() and in
I'm trying to create a function that would append two vectors together, but I
I am trying to create a new Element in my javascript code and append
How to append text to a text file in C++? And create a new
i create some links on the fly ... $('input[name=iplus]').click(function() { $(ol).append(<a href='#' title='delposition' class='beschr-+($(#billsumary
I want to create some DOM nodes with jQuery, append them to the html
I'm using os.listdir and a file to create a dictionary. I'm getting keys and
How do I create a nested dictionary in python So, I want the data
Suppose I want to create a dictionary that maps digits to numbers less than

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.