I have two files which are a and b. I want to import certain information from data b to data a with the unique id from every response.
data
a= [{'id':'abc23','name':'aa','age':'22',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc25','name':'bb','age':'32',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc60','name':'cc','age':'24',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}}]
b=[{'id':'abc23','read':'2','speak':'abc','write':'2'},
{'id':'abc25','read':'3','speak':'def','write':'3'},
{'id':'abc60','read':'5','speak':'dgf','write':'1'}]
Code that I used to import from b to a :
from pprint import pprint
for dest in a:
for source in b:
if source['id'] == dest['id']:
dest['data'].update(source)
pprint(a)
Output from the code that i used :
[{ 'age': '22',
'data': {'id': 'abc23', 'read': '2', 'speak': 'abc', 'write': '2'},
'id': 'abc23',
'name': 'aa',
'responses': {'a': 1, 'b': 2}},
{ 'age': '32',
'data': {'id': 'abc25', 'read': '3', 'speak': 'def', 'write': '3'},
'id': 'abc25',
'name': 'bb',
'responses': {'a': 1, 'b': 2}},
{ 'age': '24',
'data': {'id': 'abc60', 'read': '5', 'speak': 'dgf', 'write': '1'},
'id': 'abc60',
'name': 'cc',
'responses': {'a': 1, 'b': 2}}]
But... This is the output that I want:
[{'age': '22',
'data': {'read': '2', 'speak': 'abc'},
'id': 'abc23',
'name': 'aa',
'responses': {'a': 1, 'b': 2}},
{'age': '32',
'data': {'read': '3', 'speak': 'def'},
'id': 'abc25',
'name': 'bb',
'responses': {'a': 1, 'b': 2}},
{'age': '24',
'data': {'read': '5', 'speak': 'dgf'},
'id': 'abc60',
'name': 'cc',
'responses': {'a': 1, 'b': 2}}]
It can't work the way you want with your code.
You do
dest['data'].update(source)
where source is
{'id':'abc23','read':'2','speak':'abc','write':'2'}
and dest['data'] is {'read':'','speak':''}.
When you update it will add all key-value pairs to dest['data'] and preserve the ones that won't be overwritten.
from pprint import pprint
for dest in a:
for source in b:
if source['id'] == dest['id']:
dest['data'] = {k: v for k, v in source.items() if k in dest.get('data', {})}
pprint(a)
This one will look for all the fields that are 'updateable' for each case. You might want to hardcode it, depending on your use case.
This is one approach by changing b to a dict for easy lookup.
Ex:
a= [{'id':'abc23','name':'aa','age':'22',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc25','name':'bb','age':'32',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc60','name':'cc','age':'24',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}}]
b=[{'id':'abc23','read':'2','speak':'abc','write':'2'},
{'id':'abc25','read':'3','speak':'def','write':'3'},
{'id':'abc60','read':'5','speak':'dgf','write':'1'}]
b = {i.pop('id'): i for i in b} #Convert to dict key = ID & value = `read`, `speak`, `write`
for i in a:
i['data'].update(b[i['id']]) #Update list
print(a)
Output:
[{'age': '22',
'data': {'read': '2', 'speak': 'abc', 'write': '2'},
'id': 'abc23',
'name': 'aa',
'responses': {'a': 1, 'b': 2}},
{'age': '32',
'data': {'read': '3', 'speak': 'def', 'write': '3'},
'id': 'abc25',
'name': 'bb',
'responses': {'a': 1, 'b': 2}},
{'age': '24',
'data': {'read': '5', 'speak': 'dgf', 'write': '1'},
'id': 'abc60',
'name': 'cc',
'responses': {'a': 1, 'b': 2}}]
Related
List1 = ["1-Delphinia-65.61.138.207",
"2-Lennie-74.37.240.220",
"3-Shayne-174.76.131.156",
"4-Veriee-59.20.115.49",
"5-Val-172.101.94.229",
"6-Lanny-1.16.47.151",
"7-Laureen-117.2.197.11",
"8-Kristyn-63.21.195.62",
"9-Arlana-92.84.0.112",
"10-Arney-49.145.219.15"]
Transform the list into a dictionary with items in the following format
{
“Delphine” : {
“id” : 1,
“Ipaddr”: 65.61.138.207
},
“Lennie” : { ……. },
…….
}
Use dictionary comperhension:
>>> {name: {'id': int(id_), 'Ipaddr': ipaddr} for id_, name, ipaddr in map(lambda s: s.split('-'), List1)}
{'Delphinia': {'id': 1, 'Ipaddr': '65.61.138.207'},
'Lennie': {'id': 2, 'Ipaddr': '74.37.240.220'},
'Shayne': {'id': 3, 'Ipaddr': '174.76.131.156'},
'Veriee': {'id': 4, 'Ipaddr': '59.20.115.49'},
'Val': {'id': 5, 'Ipaddr': '172.101.94.229'},
'Lanny': {'id': 6, 'Ipaddr': '1.16.47.151'},
'Laureen': {'id': 7, 'Ipaddr': '117.2.197.11'},
'Kristyn': {'id': 8, 'Ipaddr': '63.21.195.62'},
'Arlana': {'id': 9, 'Ipaddr': '92.84.0.112'},
'Arney': {'id': 10, 'Ipaddr': '49.145.219.15'}}
Other approach, using a dictionary comprehension:
{name: {'id': ID, 'Ipaddr': ip} for s in List1 for ID, name, ip in [s.split('-')]}
output:
{'Delphinia': {'id': '1', 'Ipaddr': '65.61.138.207'},
'Lennie': {'id': '2', 'Ipaddr': '74.37.240.220'},
'Shayne': {'id': '3', 'Ipaddr': '174.76.131.156'},
'Veriee': {'id': '4', 'Ipaddr': '59.20.115.49'},
'Val': {'id': '5', 'Ipaddr': '172.101.94.229'},
'Lanny': {'id': '6', 'Ipaddr': '1.16.47.151'},
'Laureen': {'id': '7', 'Ipaddr': '117.2.197.11'},
'Kristyn': {'id': '8', 'Ipaddr': '63.21.195.62'},
'Arlana': {'id': '9', 'Ipaddr': '92.84.0.112'},
'Arney': {'id': '10', 'Ipaddr': '49.145.219.15'}}
You can simply use this code:
List1 = ["1-Delphinia-65.61.138.207", "2-Lennie-74.37.240.220", "3-Shayne-174.76.131.156", "4-Veriee-59.20.115.49", "5-Val-172.101.94.229", "6-Lanny-1.16.47.151", "7-Laureen-117.2.197.11", "8-Kristyn-63.21.195.62", "9-Arlana-92.84.0.112", "10-Arney-49.145.219.15"]
final_dict = {}
for item in List1:
data = item.split('-')
final_dict[data[1]] = {'id':int(data[0]), 'Ipaddr': data[2]}
print(final_dict)
This is how I'd do it with my basic python knowledge
new_dict= {}
for item in List1:
newitem=item.split("-")
new_dict[newitem[1]]={'id':int(newitem[0]),'ip':newitem[2]}
print(new_dict)
Output is
{
"Delphinia":{
"id":1,
"ip":"65.61.138.207"
},
"Lennie":{
"id":2,
"ip":"74.37.240.220"
},
"Shayne":{
"id":3,
"ip":"174.76.131.156"
},
"Veriee":{
"id":4,
"ip":"59.20.115.49"
},
"Val":{
"id":5,
"ip":"172.101.94.229"
},
"Lanny":{
"id":6,
"ip":"1.16.47.151"
},
"Laureen":{
"id":7,
"ip":"117.2.197.11"
},
"Kristyn":{
"id":8,
"ip":"63.21.195.62"
},
"Arlana":{
"id":9,
"ip":"92.84.0.112"
},
"Arney":{
"id":10,
"ip":"49.145.219.15"
}
def Convert(lst):
res_dct = {lst[i+1]: {"id":lst[i],"Ipaddr":lst[i + 2]} for i in range(0,len(lst), 3)}
return res_dct
final_dict ={}
for i in list1:
l =(i.split('-'))
new = Convert(l)
final_dict.update(new)
output >> final_dict
{'Delphinia': {'id': '1', 'Ipaddr': '65.61.138.207'},
'Lennie': {'id': '2', 'Ipaddr': '74.37.240.220'},
'Shayne': {'id': '3', 'Ipaddr': '174.76.131.156'},
'Veriee': {'id': '4', 'Ipaddr': '59.20.115.49'},
'Val': {'id': '5', 'Ipaddr': '172.101.94.229'},
'Lanny': {'id': '6', 'Ipaddr': '1.16.47.151'},
'Laureen': {'id': '7', 'Ipaddr': '117.2.197.11'},
'Kristyn': {'id': '8', 'Ipaddr': '63.21.195.62'},
'Arlana': {'id': '9', 'Ipaddr': '92.84.0.112'},
'Arney': {'id': '10', 'Ipaddr': '49.145.219.15'}}
I have a data structure. It looks as follows:
data = [[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2A', 'name': 'child', 'steps': 1},
{'id': '3A', 'name': 'grandChild-A', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2A', 'name': 'child', 'steps': 1},
{'id': '3B', 'name': 'grandChild-B', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3A', 'name': 'grandChild-C', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3B', 'name': 'grandChild-D', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3C', 'name': 'grandChild-E', 'steps': 2},
{'id': '4A', 'name': 'final', 'steps': 3}
],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2', 'name': 'child', 'steps': 1},
]
]
How my expected output is
expected output
output = {
"1" : {
"2A": {
"3A": "grandChild-A",
"3B": "grandChild-B"
},
"2B": {
"3A": "grandChild-C",
"3B": "grandChild-D",
"3C": {
"4A": "final"
}
},
"2":"child"
}
}
How can I do that? I wanted to use the enumerator, But I always everything inside 1.
Thanks in advance
Update:
I have tried the following code:
parent = data[0][0]["id"]
dict_new = {}
dict_new[parent] = {}
for e in data:
for idx, item in enumerate(e):
display(item)
if idx>0:
dict_new[parent][e[idx]["id"]] = e[idx]["name"]
You can try:
d = {}
root = d
for L in data:
d = root
for M in L[:-1]:
d = d.setdefault(M["id"], {})
d[L[-1]["id"]] = L[-1]['name']
The idea is to follow each list to build a tree (thus d.setdefault(M["id"], {}). The leaf is handled differently, because it has to be the value of 'name'.
from pprint import pprint
pprint(root)
Output:
{'1': {'2': 'child',
'2A': {'3A': 'grandChild-A', '3B': 'grandChild-B'},
'2B': {'3A': 'grandChild-C',
'3B': 'grandChild-D',
'3C': {'4A': 'final'}}}}
The solution above won't work for the following input:
data = [[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1}]],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3A', 'name': 'grandChild-C', 'steps': 2}]]
Iterating over the second list will try to add a new element 3A -> grandChild-C to the d['1']['2B'] dict. But d['1']['2B'] is not a dict but the 'child' string here, because of the first list.
When we iterate over the elements, we check if the key is already mapped and otherwise create a new dict (that's the setdefault job). We can also check if the key was mapped to a str, and if that's the case, replace the string by a fresh new dict:
...
for M in L[:-1]:
if M["id"] not in d or isinstance(d[M["id"]], str):
d[M["id"]] = {}
d = d[M["id"]]
...
Output:
{'1': {'2B': {'3A': 'grandChild-C'}}}
I fixed your data: (missing comma)
data = [[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2A', 'name': 'child', 'steps': 1},
{'id': '3A', 'name': 'grandChild-A', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2A', 'name': 'child', 'steps': 1},
{'id': '3B', 'name': 'grandChild-B', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3A', 'name': 'grandChild-C', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3B', 'name': 'grandChild-D', 'steps': 2}],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2B', 'name': 'child', 'steps': 1},
{'id': '3C', 'name': 'grandChild-E', 'steps': 2},
{'id': '4A', 'name': 'final', 'steps': 3}
],
[{'id': '1', 'name': 'parent', 'steps': 0},
{'id': '2', 'name': 'child', 'steps': 1},
]
]
And I came up with this code:
output = {}
#print(data)
for lis in data:
o = output
ln = len(lis) - 1
for idx,d in enumerate(lis):
id = d['id']
if idx == ln:
o[id] = d['name']
else:
if id not in o:
o[id] = {}
o = o[id]
print('Result:')
print(output)
I want to ask if we can filtered id that contain certain word only in python.
I have these two json files. and I want to filter the id for only contain 'def###'?
a= [{'id':'abc23','name':'aa','age':'22',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc25','name':'bb','age':'32',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'abc60','name':'cc','age':'24',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'def23','name':'aa','age':'22',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'def25','name':'bb','age':'32',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'def60','name':'cc','age':'24',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}}]
The output should be:
ID 'def' only will be exis.
[{'id':'def23','name':'aa','age':'22',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'def25','name':'bb','age':'32',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}},
{'id':'def60','name':'cc','age':'24',
'data':{'read':'','speak':''},
'responses':{'a':1,'b':2}}]
Use list comprehension with startswith:
a = [x for x in a if x['id'].startswith('def')
Or filter by first 3 characters:
a = [x for x in a if x['id'][:3] == 'def']
If you want to check if the id key contains certain word for ex., def in its value, you can simply do the following:
for dict_row in a:
if 'def' in dict_row['id']:
print(dict_row)
Output
{'id': 'def23', 'name': 'aa', 'age': '22', 'data': {'read': '', 'speak': ''}, 'responses': {'a': 1, 'b': 2}}
{'id': 'def25', 'name': 'bb', 'age': '32', 'data': {'read': '', 'speak': ''}, 'responses': {'a': 1, 'b': 2}}
{'id': 'def60', 'name': 'cc', 'age': '24', 'data': {'read': '', 'speak': ''}, 'responses': {'a': 1, 'b': 2}}
You can use a list comprehension to have a list of your returned dictionaries:
def_list = [dict_row for dict_row in a if 'def' in dict_row['id']]
I have list as follows:
data = [
{'items': [
{'key': u'3', 'id': 1, 'name': u'Typeplaatje'},
{'key': u'2', 'id': 2, 'name': u'Aanduiding van het chassisnummer '},
{'key': u'1', 'id': 3, 'name': u'Kilometerteller: Kilometerstand '},
{'key': u'5', 'id': 4, 'name': u'Inschrijvingsbewijs '},
{'key': u'4', 'id': 5, 'name': u'COC of gelijkvormigheidsattest '}
], 'id': 2, 'key': u'B', 'name': u'Onderdelen'},
{'items': [
{'key': u'10', 'id': 10, 'name': u'Koppeling'},
{'key': u'7', 'id': 11, 'name': u'Differentieel '},
{'key': u'9', 'id': 12, 'name': u'Cardanhoezen '},
{'key': u'8', 'id': 13, 'name': u'Uitlaat '},
{'key': u'6', 'id': 15, 'name': u'Batterij'}
], 'id': 2, 'key': u'B', 'name': u'Onderdelen'}
]
And I want to sort items by key.
Thus the wanted result is as follows:
res = [
{'items': [
{'key': u'1', 'id': 3, 'name': u'Kilometerteller: Kilometerstand '},
{'key': u'2', 'id': 2, 'name': u'Aanduiding van het chassisnummer '},
{'key': u'3', 'id': 1, 'name': u'Typeplaatje'},
{'key': u'4', 'id': 5, 'name': u'COC of gelijkvormigheidsattest '},
{'key': u'5', 'id': 4, 'name': u'Inschrijvingsbewijs '},
], 'id': 2, 'key': u'B', 'name': u'Onderdelen'},
{'items': [
{'key': u'6', 'id': 15, 'name': u'Batterij'},
{'key': u'7', 'id': 11, 'name': u'Differentieel '},
{'key': u'8', 'id': 13, 'name': u'Uitlaat '},
{'key': u'9', 'id': 12, 'name': u'Cardanhoezen '},
{'key': u'10', 'id': 10, 'name': u'Koppeling'}
], 'id': 2, 'key': u'B', 'name': u'Onderdelen'}
]
I've tried as follows:
res = []
for item in data:
new_data = {
'id': item['id'],
'key': item['key'],
'name': item['name'],
'items': sorted(item['items'], key=lambda k : k['key'])
}
res.append(new_data)
print(res)
The first is sorted fine, but the second one not.
What am I doing wrong and is there a better way of doing it?
Your sort is wrong in the second case because the keys are strings, and strings are sorted by their first character which is '1' if your key is '10'. A slight modification to your sorting function would do the trick:
'items': sorted(item['items'], key=lambda k : int(k['key'])
I'm doing an int because you want to sort them as if they are numbers. Here it is in your code:
res = []
for item in data:
new_data = {
'id': item['id'],
'key': item['key'],
'name': item['name'],
'items': sorted(item['items'], key=lambda k : int(k['key']) )
}
res.append(new_data)
print(res)
And here's the result:
[{'id': 2,
'items': [{'id': 3, 'key': '1', 'name': 'Kilometerteller: Kilometerstand '},
{'id': 2, 'key': '2', 'name': 'Aanduiding van het chassisnummer '},
{'id': 1, 'key': '3', 'name': 'Typeplaatje'},
{'id': 5, 'key': '4', 'name': 'COC of gelijkvormigheidsattest '},
{'id': 4, 'key': '5', 'name': 'Inschrijvingsbewijs '}],
'key': 'B',
'name': 'Onderdelen'},
{'id': 2,
'items': [{'id': 15, 'key': '6', 'name': 'Batterij'},
{'id': 11, 'key': '7', 'name': 'Differentieel '},
{'id': 13, 'key': '8', 'name': 'Uitlaat '},
{'id': 12, 'key': '9', 'name': 'Cardanhoezen '},
{'id': 10, 'key': '10', 'name': 'Koppeling'}],
'key': 'B',
'name': 'Onderdelen'}]
You need to replace the old items in the data with the sorted items based on key numerically instead of string sort. So use int(item['key']) in sort like,
>>> data
[{'items': [{'key': '1', 'id': 3, 'name': 'Kilometerteller: Kilometerstand '}, {'key': '2', 'id': 2, 'name': 'Aanduiding van het chassisnummer '}, {'key': '3', 'id': 1, 'name': 'Typeplaatje'}, {'key': '4', 'id': 5, 'name': 'COC of gelijkvormigheidsattest '}, {'key': '5', 'id': 4, 'name': 'Inschrijvingsbewijs '}], 'id': 2, 'key': 'B', 'name': 'Onderdelen'}, {'items': [{'key': '6', 'id': 15, 'name': 'Batterij'}, {'key': '7', 'id': 11, 'name': 'Differentieel '}, {'key': '8', 'id': 13, 'name': 'Uitlaat '}, {'key': '9', 'id': 12, 'name': 'Cardanhoezen '}, {'key': '10', 'id': 10, 'name': 'Koppeling'}], 'id': 2, 'key': 'B', 'name': 'Onderdelen'}]
>>>
>>> for item in data:
... item['items'] = sorted(item['items'], key=lambda x: int(x['key']))
...
>>> import pprint
>>> pprint.pprint(data)
[{'id': 2,
'items': [{'id': 3, 'key': '1', 'name': 'Kilometerteller: Kilometerstand '},
{'id': 2, 'key': '2', 'name': 'Aanduiding van het chassisnummer '},
{'id': 1, 'key': '3', 'name': 'Typeplaatje'},
{'id': 5, 'key': '4', 'name': 'COC of gelijkvormigheidsattest '},
{'id': 4, 'key': '5', 'name': 'Inschrijvingsbewijs '}],
'key': 'B',
'name': 'Onderdelen'},
{'id': 2,
'items': [{'id': 15, 'key': '6', 'name': 'Batterij'},
{'id': 11, 'key': '7', 'name': 'Differentieel '},
{'id': 13, 'key': '8', 'name': 'Uitlaat '},
{'id': 12, 'key': '9', 'name': 'Cardanhoezen '},
{'id': 10, 'key': '10', 'name': 'Koppeling'}],
'key': 'B',
'name': 'Onderdelen'}]
So list comes with a handy method called sort which sorts itself inplace. I'd use that to your advantage:
for d in data:
d['items'].sort(key=lambda x: int(x['key']))
Results:
[{'id': 2,
'items': [{'id': 3, 'key': '1', 'name': 'Kilometerteller: Kilometerstand '},
{'id': 2, 'key': '2', 'name': 'Aanduiding van het chassisnummer '},
{'id': 1, 'key': '3', 'name': 'Typeplaatje'},
{'id': 5, 'key': '4', 'name': 'COC of gelijkvormigheidsattest '},
{'id': 4, 'key': '5', 'name': 'Inschrijvingsbewijs '}],
'key': 'B',
'name': 'Onderdelen'},
{'id': 2,
'items': [{'id': 15, 'key': '6', 'name': 'Batterij'},
{'id': 11, 'key': '7', 'name': 'Differentieel '},
{'id': 13, 'key': '8', 'name': 'Uitlaat '},
{'id': 12, 'key': '9', 'name': 'Cardanhoezen '},
{'id': 10, 'key': '10', 'name': 'Koppeling'}],
'key': 'B',
'name': 'Onderdelen'}]
I want to parse excel and put data in the model(User).Now I want to make a dictionary which has excel data. Excel is
I wrote in views.py
#coding:utf-8
from django.shortcuts import render
import xlrd
def try_to_int(arg):
try:
return int(arg)
except:
return arg
def main():
book3 = xlrd.open_workbook('./data/excel1.xlsx')
sheet3 = book3.sheet_by_index(0)
data_dict = {}
tag_list = sheet3.row_values(0)[1:]
for row_index in range(1, sheet3.nrows):
row = sheet3.row_values(row_index)[1:]
row = list(map(try_to_int, row))
data_dict[row_index] = dict(zip(tag_list, row))
print(data_dict)
main()
and it printed out {1: {'A': '', 'area': 'New York', 'C': 0, 'name': 'Blear', 'B': ''}, 2: {'A': '', 'area': 'Chicago', 'C': '', 'name': '', 'B': 0}, 3: {'A': 0, 'area': 'London', 'C': '', 'name': '', 'B': ''}, 4: {'A': '', 'area': 'Singapore', 'C': '', 'name': 'Tom', 'B': ''}, 5: {'A': 0, 'area': 'Delhi', 'C': '', 'name': '', 'B': ''}, 6: {'A': '', 'area': 'Beijing', 'C': 1, 'name': '', 'B': ''}}
But
I cannot understand why output dictionary is mess.I want to get a dictionary like
{1: {'name': 'Blear', 'area': 'New York', 'A': '', 'B': '', 'C': 0},
1: {'name': 'Blear', 'area': 'Chicago', 'A': '', 'B': 0, 'C': ''},
1: {'name': 'Blear', 'area': 'London', 'A': 50, 'B': 0, 'C': ''},
2: {'name': 'Tom', 'area': 'Singapore', 'A': '', 'B': '', 'C': ''}}・・・
What is wrong in my code? How should I fix this?