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 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

Related Questions

I want to create a python dictionary that returns me the key value for
I want to create a MSWindows Python program that would launch a new Firefox
I want to create an object in python that is a collection of around
Is there any way I can create a UAC-like environment in Python? I want
I want to create a template for all my python scripts using this autocmd
I want to be able to create a python decorator that automatically registers class
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
I have a dictionary in python like this: x = {country:{city:population}:......} and I want
How do I create a dictionary in python whose values are also a dictionary?

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.