I have a .txt file that looks like this:
Key1 Key2 Key3
Val1-A Val2-A Val3-A
Val1-B Val2-B Val3-B
....
Each field is separated by tab, how can I read the file and store it in a dictionary of lists without using any kind of for/while loop? Comprehensions are allowed
with open("file.txt", "r") as input:
#comprehension here
Thanks!
EDIT: sorry I forgot to include my attempt so far
try:
with open("file.txt", "r") as input:
line = input.readline()
line = re.split(r '\t+', line)
myDict = dict(line.strip() for line in infile)
if line == "":
raise ValueError
except IOError:
print ("Error! File is not found.")
except ValueError:
print("Error! File is empty.")