求助 提取列表中指定的值
wirte_out_files=open('test.csv','w')
eclist=[('4278000000005D5D5501', '42', '78000000', '00', '5D5D55',
'01'), ('4279000000005D5D5501', '42', '79000000', '00', '5D5D55',
'01'), ('427A000000005D5D5501', '42', '7A000000', '00', '5D5D55',
'01'), ('427B000000005D5D5501', '42', '7B000000', '00', '5D5D55',
'01'), ('4256030000003D3D1101', '42', '56030000', '00', '3D3D11',
'01'), ('4257030000003D3D1101', '42', '57030000', '00', '3D3D11',
'01'), ('4258030000003D3D1101', '42', '58030000', '00', '3D3D11',
'01'), ('429E030000006F6F3301', '42', '9E030000', '00', '6F6F33',
'01'), ('4241050000004F4F0001', '42', '41050000', '00', '4F4F00',
'01'), ('4242050000004F4F0001', '42', '42050000', '00', '4F4F00',
'01'), ('526805000000ECEC11F4', '52', '68050000', '00', 'ECEC11',
'F4'), ('436805000000EBEB1101', '43', '68050000', '00', 'EBEB11',
'01'), ('42F10B0000008A8A1101', '42', 'F10B0000', '00', '8A8A11',
'01'), ('42F20B0000008A8A1101', '42', 'F20B0000', '00', '8A8A11',
'01'), ('42F30B0000008A8A1101', '42', 'F30B0000', '00', '8A8A11',
'01'), ('42F40B0000008A8A1101', '42', 'F40B0000', '00', '8A8A11',
'01'), ('42F50B0000008A8A1101', '42', 'F50B0000', '00', '8A8A11',
'01'), ('520B100000006A6A44F4', '52', '0B100000', '00', '6A6A44',
'F4')]
totalcount=len(eclist)
ecdict={}
i=0
for i in range(totalcount):
item=eclist
i+=1
key=item[1]
if key in ecdict.keys():
ecdict[key]+=1
else:
ecdict[key]=1
print len(eclist)
key1="42"
key2="43"
wirte_out_files.write('%s,%d \n' % (key1,ecdict[key1]))
wirte_out_files.write('%s,%d \n' % (key2,ecdict[key2]))
wirte_out_files.close
以上是我的代码
我只想从LIST中提取42和43这两个的在LIST中的数量
请问该怎么改写这段代码?