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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:53:42+00:00 2026-05-14T00:53:42+00:00

I want to create a Python dictionary which holds values in a multidimensional array

  • 0

I want to create a Python dictionary which holds values in a multidimensional array that can expand.

This is the structure that the values should be stored:

userdata = {'data':[{'username':'Ronny Leech','age':'22','country':'Siberia'},{'username':'Cronulla James','age':'34','country':'USA'}]}

Let’s say I want to add another user:

def user_list():
     users = []
     for i in xrange(5, 0, -1):
       lonlatuser.append(('username','%s %s' % firstn, lastn))
       lonlatuser.append(('age',age))
       lonlatuser.append(('country',country))
     return dict(user)

This will only return a dictionary with a single value in it (since the key names are same values will overwritten). So how do I append a set of values to this dictionary?

Note: assume age, firstn, lastn, and country are dynamically generated.

  • 1 1 Answer
  • 1 View
  • 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-14T00:53:42+00:00Added an answer on May 14, 2026 at 12:53 am
    userdata = { "data":[]}
    
    def fil_userdata():
      for i in xrange(0,5):
        user = {}
        user["name"]=...
        user["age"]=...
        user["country"]=...
        add_user(user)
    
    def add_user(user):
      userdata["data"].append(user)
    

    or shorter:

    def gen_user():
      return {"name":"foo", "age":22}
    
    userdata = {"data": [gen_user() for i in xrange(0,5)]}
    
    # or fill separated from declaration so you can fill later
    userdata ={"data":None} # None: not initialized
    userdata["data"]=[gen_user() for i in xrange(0,5)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is the sort of question which indicates you really… May 16, 2026 at 11:34 am
  • Editorial Team
    Editorial Team added an answer Is there a reason you're using inline handlers? I'd get… May 16, 2026 at 11:34 am
  • Editorial Team
    Editorial Team added an answer This looks like a pretty solid tutorial covering the Google… May 16, 2026 at 11:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a datetime object, for which I want to create a date string
BerkeleyDB is the database equivalent of a Ruby hashtable or a Python dictionary except
I'm writing a class which I intend to use to create subroutines, constructor as
Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .
I've got three models that show some sort of activity on a website I'm
Does python have a full fledged email library with things for pop, smtp, pop3
I have two lists in Python: temp1 = ['One', 'Two', 'Three', 'Four'] temp2 =
Here is a problem: In my bash scripts I want to source several file

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.