我有一份字典清单,所以:
[{'point': '-2.43896484341047, 53.4369463378926',
'time': '2015-06-17 12:51:16+01:00',
'title': 'Queen and Royal Family Members Visit Manchester'},
{'point': '-0.150032043436181, 51.5402430395087',
'time': '2015-06-20 12:52:29+01:00',
'title': 'Price Harry Quits the Army to Concentrate on Charity Work'},
{'point': '-0.150032043436181, 51.5402430395087',
'time': '2015-06-26 17:01:19+01:00',
'title': 'A true friend: Ukraine president asks Tony Blair to take on advisory role'},
{'point': '-77.1075439345789, 35.456615048032',
'time': '2015-06-26 17:01:19+01:00',
'title': 'A true friend: Ukraine president asks Tony Blair to take on advisory role'}]
我希望能够搜索字典,在两个字典共享相同标题和时间的情况下,合并标题和时间并保留不同的点值,创建如下内容:
[{'point': '-2.43896484341047, 53.4369463378926',
'time': '2015-06-17 12:51:16+01:00',
'title': 'Queen and Royal Family Members Visit Manchester'},
{'point': '-0.150032043436181, 51.5402430395087',
'time': '2015-06-20 12:52:29+01:00',
'title': 'Price Harry Quits the Army to Concentrate on Charity Work'},
{'point': ['-0.150032043436181, 51.5402430395087', '-77.1075439345789, 35.456615048032'],
'time': '2015-06-26 17:01:19+01:00',
'title': 'A true friend: Ukraine president asks Tony Blair to take on advisory role'}]
提前感谢您的帮助!你知道吗
进行一次传递以收集重复的文章,第二次传递以发出分组的文章,如您所述:
尝试以下较短的解决方案:
结果存储在
ans
变量中,并具有预期的结构-尽管输出列表中的元素可能以不同的顺序出现,因为我使用set
来找出唯一的“键”:试试这个,很抱歉我的命名惯例不好:
输出:
相关问题 更多 >
编程相关推荐