I want to build two lists from a document that may vary in formatting but should roughly be two columns with some separator. each row is :
"word1"\t"word2"
for example. My lists should be "list_of_word1", "list_of_word2". I want to build them at once. I know that I could use pandas, but for some reason (the script should be able to work without specific import, only on general library), I also need to use regular document opening.
My attempt was:
list_of_word1=[]
list_of_word2=[]
((list_of_word1.extend(line.split()[0]),list_of_word2.extend(line.split()[1])) for line in open(doc))
The generator doesn't serve any purpose since extend returns None, so that may be seen as bad to use a form that won't be reused there or that might be unnecessary in the first place. Plus, I would like to know how to avoid to have to reuse the split function, that's "ok" for 2 times per line, but if I was to use the same principle on more columns, it would become very unefficient.
My try to avoid reuse split was to make it like this:
((list_of_word1.extend(linesplit0),list_of_word2.extend(linesplit1)) for line in open(doc) for (linesplit0,linesplit1) in line.split("\t"))
but that indeed doesn't work, since it doesn't find tuples to unpack. i also tried starred unpacking but that's not working.
((list_of_word1.extend(linesplit0),list_of_word2.extend(linesplit1)) for linesplit0,linesplit1 in open(doc).readline().split("\n").split("\t"))
But that somehow feels unsatisfactory, too contrived. What do you think?