python把合约按品种分一下类
作者:互联网
# coding=utf-8
abc=['jm2101', 'm2105', 'c2105', 'pg2012', 'cs2101', 'cs2105', 'p2101', 'ru2101', 'ru2103', 'RM101', 'RM105', 'CF101', '', 'y2101', 'sc2012', 'i2101-P-700', 'i2101-P-750', 'au2012C408', 'CF101C14400', 'CF101C15400', 'IF2011', 'm2101-C-3150', 'm2101-C-3300', 'y2105', 'i2105', 'ag2012', 'FG101', 'RM101C2600', 'RM101C2700', 'IO2011-C-4900', 'IO2011-C-5000', 'pg2012-C-3900', 'm2101-C-3350', 'c2101-C-2480', 'c2101-C-2520', 'p2105', 'au2012', 'au2012C456', 'ru2101C15000', 'ru2101C16000', 'm2101-C-3400', 'i2101', 'i2101-P-800', 'au2012C440', 'au2012C416', 'IH2011', 'MA101', 'c2109', 'cs2109', 'c2101-C-2620', 'c2101-C-2640', 'MA101C2150', 'm2101-C-3200', 'IO2011-C-4950', 'm2101-C-3250', 'sc2101', 'CF105', 'ru2101C16500', 'CF101C14600', 'au2104', 'au2102C376', 'ru2105', 'cu2101C57000', 'cu2101C58000', 'IO2012-C-5500']
数字=['0','1','2','3','4','5','6','7','8','9']
字典={}
for ix in abc:
品种=''
for i in range(len(ix)):
if 数字.count(ix[i])==0:
#print("字母 ",ix[i])
品种=品种+str(ix[i])
else :
if len(ix)>7:
品种=品种+'期权'
if 品种 in 字典:
#print(品种,"在字典里")
if 字典[品种].count(ix)==0:
字典[品种].append(ix)
#print(品种,"添加合约",ix)
#print(品种,字典[品种])
else :
合约=[ix]
字典[品种]=合约
#print("添加字典 ",品种,字典[品种])
#print("品种 ",品种)
#print("数值 ",ix[i])
break
#print("合约",ix)
print(字典)
print(len(字典))
标签:ix,c2101,python,品种,print,m2101,合约,字典 来源: https://blog.csdn.net/qq_30121869/article/details/113434273