My text file format is:
apple very healthy
orange tangy and juicy
banana yellow in color and yummy
I need to create either two lists:
l1 = ['apple','orange','banana']
l2=['very healthy','tangy and juicy','yellow in color and yummy']
or convert the values into a dictionary:
d1={'apple':'very healthy','orange':'tangy and juicy','banana':'yellow in color and yummy'}
The first two columns in the file are separated by tab.
I tried the following code to change it to two lists and then convert it into a dictionary:
l1=[]
l2=[]
d={}
read_file=open('edges.txt','r')
split= [line.strip() for line in read_file]
for line in split:
l1.append(line.split('\t')[0])
l2.append(line.split('\t')[1:])
d=dict(zip(l1,l2))
print d
I am getting some incorrect values. I am newbie to python..