I have a loop to read in data, but the numbering isn't continuous. Thus, I want to skip specific values. But I only knew how to skip one, not a set of values. This is my example code:
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)
But instead of "x!=9" I need something like if x!= one of those values [9,10,12,16,......] (edit: the values are stored in a list). Any suggestions?
forloop is just an example? I'd not use a list comprehension there, as that creates a whole list first; use a generator expression at least:for n in (x for x in range(2, m) if x != 9):np.strinstead of directly calling thestrconstructor? BTW, you can do that padding without usingif...elif...else. Seestr.zfillandstr.rjust.