我有一个如下的输入文件:
5181 zzzzzzzzzzzzzzzz
6220 aaaaaaaa
1498 bbbbbbbbb
1498 ccccccccccc
我想对具有相同id号的行进行分组。所以会是这样的:
5181 zzzzzzzzzzzzzzzz
6220 aaaaaaaa
1498 bbbbbbbbbb
1498 ccccccccccc
我试图创建一个有3个键的字典,但无法附加所有值
这是我写的:
for i in package_ids:
dict2[i] = (x for x in textt if int(i) in textt is True)
您可以使用
collections.defaultdict
:没有
defaultdict
:假设id数字和行的文本用tab(s)
\t
分隔,简单排序:输出:
相关问题 更多 >
编程相关推荐