0
我有一個django項目,從我們的另一個應用程序獲取一些數據。數據看起來像這樣:比較和刪除api數據
{u' updated': u'2017-04-03T22:30:53.760278 Z',
u'added': u'2017-04-03T22:30:53.760197 Z',
u'name':u'Jean Lamb,
1942- ', u' authority':{
u'id':2,
u'added_by':2,
u'name':u'VIAF'
},
u'local_identifier':u'85363862',
u'concept_type':{
u'id':5,
u'identifier': u'viaf:personal',
u'name':u'',
u'description':None
},
u'identifier': u'http://viaf.org/viaf/85363862',
u'identities':[
{
u'part_of':{
u'id':1,
u'added_by':2,
u'name': u'builtin:Conceptpower'
},
u'added': u'2017-04-03T22:33:20.476637 Z',
u'name':u'Jean Lamb',
u'confidence':1.0,
u'updated': u'2017-04-03T22:33:20.476699 Z',
u'concepts':[
u'http://viaf.org/viaf/85363862',
u'http://www.digitalhps.org/concepts/CONpeSHC70qxNC0'
],
u'id':208,
u'added_by':{
u'username':u'erickjones',
u'email':u'[email protected]'
}
},
{
u'part_of':{
u'id':1,
u'added_by':2,
u'name': u'builtin:Conceptpower'
},
u'added': u'2017-04-03T22:35:02.546054 Z',
u'name':u'Jean Lamb',
u'confidence':1.0,
u'updated': u'2017-04-03T22:35:02.546116 Z',
u'concepts':[
u'http://viaf.org/viaf/85363862',
u'http://www.digitalhps.org/concepts/CONpeSHC70qxNC0'
],
u'id':209,
u'added_by':{
u'username':u'erickjones',
u'email':u'[email protected]'
}
},
現在我有一個函數可以通過並比較身份中的概念。我想要做的是刪除重複的概念。字典和列表的嵌套正在拋棄我。我一直在嘗試的是:
del results[i]["identities"][z]["concepts"]
任何想法爲什麼這不起作用?
這裏是我的循環櫃面有人有興趣:
while (i != di):
test = results[i]["identities"]
if results[i]["identities"]:
z = 0
while (z != len(results[i]["identities"])):
con1 = results[i]["identities"][z]["concepts"]
print "this is con1: %s", con1
if z != len(results[i]["identities"]):
z = z + 1
else:
break
if z != len(results[i]["identities"]):
con2 = results[i]["identities"][z]["concepts"]
print "this is con2: %s", con2
if set(con1) == set(con2):
del results[i]["identities"][z]["concepts"]
else:
break
i = i + 1
你是對的我的錯。不幸的是,改變比較並不能解決我的問題 – Taylor