Couldn’t find an answer to this solution, so once I figured it out I thought I’d re-post my solution…
I was looking for a way of taking a user input (sys.argv[1]) and use this value to perform a lookup in a CSV file for another value in column x (e.g. 5). This would be part of a larger script and I would use the looked-up value as a test.
My example csv would be:
col0,col1,col2,col3,col4
a,foo,bar,blah,1
b,foo,bar,blah,2
c,foo,bar,blah,3
d,foo,bar,blah,4
e,foo,bar,blah,5
f,foo,bar,blah,6
g,foo,bar,blah,7
h,foo,bar,blah,8
i,foo,bar,blah,9
j,foo,bar,blah,10
k,foo,bar,blah,11
l,foo,bar,blah,12
m,foo,bar,blah,13
n,foo,bar,blah,14
o,foo,bar,blah,15
p,foo,bar,blah,16
q,foo,bar,blah,17
r,foo,bar,blah,18
s,foo,bar,blah,19
t,foo,bar,blah,20
u,foo,bar,blah,21
v,foo,bar,blah,22
w,foo,bar,blah,23
x,foo,bar,blah,24
y,foo,bar,blah,25
z,foo,bar,blah,26
I had a quick look at your Javascript question, and if you’re only ever mapping char->position in alphabet, what about the following?
And if you wanted to pre-generate a lookup table, then something like:
Otherwise, since CSV files are generally relativey small you could just load the entire file to RAM to avoid repeated sequential lookups later (as long as the CSVs not so large it’ll put your machine in a coma)