我要把这个拿出来: 以RAM处理器为首的硬盘价格警惕
2GB core2due 12inch 300GB 30000 1year
4GB i3 14inch 500GB 40000 2year
8GB dualcore 15inch 1TB 40000 1year
2GB dualcore 12inch 500GB 40000 1year
16GB i5 15inch 1TB 30000 1year
8GB core2due 12inch 300GB 30000 2year
但我不知道该怎么办 我的例子是
不能提供这个输出 代码就是我的例子
parts=['RAM','Processor','LED','HDD','Price','waranty']
processor=['core2due','i3','i2','dualcore','i5','i7']
ram=['2GB','4GB','8GB','16GB','1TB','2TB']
price=['30000','40000','50000','60000','35000','29000']
hdd=['150GB','200GB','300GB','500GB','1TB','2TB']
waranty=['6month','1year','2year','3year','4year','5year']
led=['9inch','10inch','12inch','14inch','15inch','16inch']
com1={}
com2={}
com3={}
com4={}
com5={}
com6={}
j=0
shopcomputer={}
for i in range(0,len(parts)):
com1[parts[i]]=ram[j]
com2[parts[i]]=processor[j]
com3[parts[i]]=led[j]
com4[parts[i]]=hdd[j]
com5[parts[i]]=price[j]
com6=[parts[i]]=waranty[j]
j=j+1
shopcomputer[1] = com1
shopcomputer[2] = com2
shopcomputer[3] = com3
shopcomputer[4] = com4
shopcomputer[5] = com5
shopcomputer[6] = com6
for i in parts:
print '\t',i,
print '\n',
for no1 in shopcomputer:
print shopcomputer[no1]['RAM'].rjust(10,),shopcomputer[no1] ['Processor'].rjust(5,),shopcomputer[no1]['LED'].rjust(16,),shopcomputer[no1] ['HDD'].rjust(7,),shopcomputer[no1]['Price'].rjust(8,),shopcomputer[no1] ['waranty'].rjust(8,)
print shopcomputer
我已经纠正了你的字典格式,现在你可以应用任何格式技术和打印出所需的结果。你知道吗
您可以使用
format
:你首先需要确定如何建立字典。幸运的是,通过
zip
将列表ping在一起可以很容易地做到这一点。然后使用format(**dict)
是格式化输出的最简单方法。你知道吗相关问题 更多 >
编程相关推荐