from itertools import groupby
#input
l = [['Cautus B.V.', 'plein 92', '1129008', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus B.V.', 'Wei 9-11', '1019123', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus B.V.', 'plein 92', '1129008', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus B.V.', 'Wei 9-11', '1019123', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['De company', 'tiellaan 42', 'KD0022232', '13', 'AVB', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
['De company', 'tiellaan 42', 'KD0022232', '13', 'DAS', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
['Slever ', 'klopt 42', 'KD2220115', '17', 'AVB', 'Geachte heer Slever', 'De heer T. Slever']]
#script
l_clean = sorted(zip(zip(*l)[1], zip(*l)[4],))
l_final = [(k, zip(*v)[1]) for k,v in groupby(l_clean, key = lambda x:x[0])]
for k,v in l_final:
print k,list(v)
#My output is:
Wei 9-11 ['AVB', 'BEDR']
klopt 42 ['AVB']
plein 92 ['AVB', 'BEDR']
tiellaan 42 ['AVB', 'DAS']
问题
我的问题是我似乎无法将其他数据添加到输出中,我还想在输出中包含的数据是:
['Cautus B.V.','1019123', '10', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'](not only for this entry but for all entry's)
我尝试了所有更改/添加密钥等的方法,但它似乎不起作用。我知道我的英语很模糊,所以如果我需要澄清一些词或任何事情,就这么说吧。已经提前谢谢了。