有时候获取列表数据会发现有重复标题,我们将数据放入字典中,想直接去除重复的键值,找了很久,终于找到了字典去除方法。
示例
l4=[{'host':'氨甲酰甲胆碱有哪些作用?', 'cpu':'KXijmqaaQDZh_2JdpYiErA'},{'host':'氨甲酰胆碱的作用特点是什么?', 'cpu':'VsBPUrr1ZMJsbw_2zDRc6w'},{'host':'氨甲酰胆碱的作用特点是什么?', 'cpu':'ZX-0XEAeZ6Nj1Bp__4Hk_g'}, {'host':'氯化氨甲酰甲胆碱俗称?', 'cpu':'ns0B260FmeDI49CPWNTWzQ'},{'host':'氨甲酰胆碱的作用特点是什么?', 'cpu':2},{'host':'compute23', 'cpu':2}, {'host':'compute24', 'cpu':2}] def cf_url(l3:list): l4 = [] l4.append(l3[0]) for dict in l3: k = 0 for item in l4: if dict['host'] != item['host']: k = k + 1 else: break if k == len(l4): l4.append(dict) return l4
执行结果
[{'host': '氨甲酰甲胆碱有哪些作用?', 'cpu': 'KXijmqaaQDZh_2JdpYiErA'}, {'host': '氨甲酰胆碱的作用特点是什么?', 'cpu': 'VsBPUrr1ZMJsbw_2zDRc6w'}, {'host': '氯化氨甲酰甲胆碱俗称?', 'cpu': 'ns0B260FmeDI49CPWNTWzQ'}, {'host': 'compute23', 'cpu': 2}, {'host': 'compute24', 'cpu': 2}]
I was excited to uncover this website. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you bookmarked to look at new things in your site.