hello all,
I have the following text file:
1,a,good
1,a,bad
1,b,good
1,c,bad
would like to create a dictionary:
have been trying:
unfortunately I keep getting where 'bad' is being appended to 'v2':
I have the following text file:
1,a,good
1,a,bad
1,b,good
1,c,bad
would like to create a dictionary:
Code:
d={1:{'v1':(a,b,c), 'v2':(good)}}
Code:
for line in lines:
uh, tf, tp = line.split('%')
if uh in d:
f=d[uh]['v1']
if tf not in f:
f.append(tf)
p=d[uh]['v2']
if tp is not 'bad' and tp not in p:
p.append(tp)
else:
d[uh]={'v1':[], 'v2':[]}
Code:
d={'1': {'v1': ['a', 'b', 'c'], 'v2': ['bad', 'good']}}
Comment