I have a .tsv consisting of a key and two values. I want to create two dictionaries, one mapping from the key to the first value for each line in the file, and the other mapping from the key to the second value. I can do this:
v1Dict = {key: v1 for (key,v1,v2) in (line.split("\t") for line in (open (myinputfile)))}
v2Dict = {key: v2 for (key,v1,v2) in (line.split("\t") for line in (open (myinputfile)))}
But that's obviously inefficient as it reads/parses the entire file twice.
Alternately, I can do this:
v1Dict = {}
v2Dict = {}
for (key,v1,v2) in (line.split("\t") for line in (open (myinputfile))):
v1Dict[key]=v1
v2Dict[key]=v2
Is that the "best" way to do it?