i have a big (nearly a million lines) file that is being read in, one line at a time. each line is .split() and there are about 3 dozen tokens for each line. several tokens are checked to select which lines are to be used. the check is an equality check for a few different tokens. the tokens being checked are not contiguous, such as 4, 5, 9, 10, and 12 are checked. i am doing these checks with a big long if statement with lots of ands. i am wondering if there is any sweeter way to code this kind of thing. a program i am working on today is doing a lot of this kind of thing, from lots of cloud data i have.
datadict = {} for line in sys.stdin: tokens = line.rstrip().split() if tokens[4] == 'foo' and\ tokens[5] == 'bar' and\ tokens[9] == 'xyzzy' and\ tokens[10] == 'yzzyx' and\ tokens[12] == 'Skaperen': processed += 1 datadict[tokens[0]] = (tokens[1],tokens[2],tokens[3]) elif tokens[4] == 'bar' and\ tokens[5] == 'foo' and\ tokens[9] == 'yzzyx' and\ tokens[11] == 'xyzzy' and\ tokens[12] == 'Skapare': processed += 1 datadict[tokens[0]] = (tokens[2],tokens[1],tokens[3]) else: skipped += 1comparing long slices is not practical since the data to be checked is on either side of data that can vary.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.