python三元表达式

2020-07-16  本文已影响0人  山猪打不过家猪
b=[i.strip('%') if '%' in i else i for i in a]
[(tuple([erpId, day] + list(j))) for i in a for j in i]
a =(['2,621', '35'],['210,852'],['2,398'],['12', '43'],['1', '09'])

a = [i[0].replace(',', '') if len(i)==1 else ((i[0] + '.' + i[1]).replace(',', '')) for i in a ]

>>>
['2621.35', '210852', '2398', '12.43', '1.09']
import re
a =[ ('636710425400', 318.09, 1, 5, '2021-04-08'), ('616873233546;\n617383035002;\n585098358905', 62.54, 1, 5, '2021-04-08'), ('39856905008', 120.5, 1, 5, '2021-04-08'), ('610474183283', 84.6, 1, 5, '2021-04-08'), ('625046034602;\n625333579394', 93.01, 1, 5, '2021-04-08'), ('608727393051;\n616119541298;\n610494565658;\n633320454564', 122.55, 1, 5, '2021-04-08')]
ccc =[(re.findall("(\d+);",str(i[0]))[0],i[1],i[2],i[3],i[4]) if ';' in str(i[0]) else i for i in a ]
for i in ccc:
    print(i)

>>>
('636710425400', 318.09, 1, 5, '2021-04-08')
('616873233546', 62.54, 1, 5, '2021-04-08')
('39856905008', 120.5, 1, 5, '2021-04-08')
('610474183283', 84.6, 1, 5, '2021-04-08')
('625046034602', 93.01, 1, 5, '2021-04-08')
('608727393051', 122.55, 1, 5, '2021-04-08')
上一篇下一篇

猜你喜欢

热点阅读