I want to create a Python dictionary that contains values in multidimensional agreement, and it should be expandable, this is the structure in which the values should be stored: -
userdata = {'data':[{'username':'Ronny Leech','age':'22','country':'Siberia'},{'username':'Cronulla James','age':'34','country':'USA'}]}
Suppose 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 return a dictionary with a single value in it (since the key names will be the same values will be overwritten). So how do I add a set of values to this dictionary.
Note: it is assumed that age, firstn, lastn, and country are dynamically generated.
Thanks.
python
Switch
source share