作者:mobiledu2502877493 | 来源:互联网 | 2022-12-06 13:31
我有一个循环读取数据,但编号不连续.因此,我想跳过具体的值.但我只知道如何跳过一个,而不是一组值.这是我的示例代码:
for n in [x for x in range(2,m) if x!=9]:
if n <10:
statiOnsnr= '00'+np.str(n)
elif n <100:
statiOnsnr= '0'+np.str(n)
else:
statiOnsnr= np.str(n)
但是代替"x!= 9"我需要像x!=其中一个值[9,10,12,16,......](编辑:值存储在列表中).有什么建议?
1> Martijn Piet..:
您可以测试该值是否为集合的成员:
[... if x not in {9, 10, 12, 16, }]
设置成员资格测试是O(1)恒定时间(如此之快!).