【发布时间】:2021-05-21 07:05:43
【问题描述】:
我是 python 新手,我正在尝试根据某些条件将字典列表拆分为单独的字典列表。
这就是我的列表的样子:
[{'username': 'AnastasiadesCY',
'created_at': '2020-12-02 18:58:16',
'id': 1.33421029132062e+18,
'language': 'en',
'contenttype': 'text/plain',
'content': 'Pleased to participate to the international conference in support of the Lebanese people. Cypriot citizens, together with the Government ????????, have provided significant quantities of material assistance, from the day of the explosion until today.\n\n#Lebanon ????????'},
{'username': 'AnastasiadesCY',
'created_at': '2020-11-19 18:13:06',
'id': 1.32948788307022e+18,
'language': 'en',
'contenttype': 'text/plain',
'content': '#Cyprus stand ready to support all efforts towards a coordinated approach of vaccination strategies across Europe, that will prove instrumental in our fight against the pandemic.\n\nUnited Against #COVID19 \n\n#EUCO'},...
我想将具有相同用户名的所有列表元素拆分并分组到单独的字典列表中。列表的元素 - 所以每个字典 - 按用户名排序。
有没有办法遍历字典并将每个元素附加到列表中,直到“item 1”中的用户名等于“item 1 + 1”中的用户名等等?
感谢您的帮助!
【问题讨论】:
标签: python list loops dictionary if-statement