Andrea Hi guys,this is my first post. my "programming" background is perlish scriptingand now I am learning python. I need to create a dictionary of listfrom a file. Normally in perl I use to do like: while(<IN>){@info=split(/ +/,$_);push (@{$tmp{$info[0]}},$info[1]);} and thenforeach $key (keys %tmp){print "$key -@{$tmp{$key}}\n";}i get 2 -1 2 3 47 -7 8 9 10 in python I tried:b={}a=[]for line in fl.readlines():info=lines.split()b[info[0]] = a.append(info[1]) and thenfor i in b:print i,b[i]i get2 None7 None data file is:2 12 22 32 47 77 87 97 10 Any help??Thanks in advanceBest Regards Andrea 推荐答案 _ ); push(@ {_);push (@{ tmp { info [0]}},info[0]}}, 这篇关于文件列表的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 05:56