I have a file with data like this. The '>' serves as identifier.
>test1
this is line 1
hi there
>test2
this is line 3
how are you
>test3
this is line 5 and
who are you
I'm trying to create a dictionary
{'>test1':'this is line 1hi there','>test2':'this is line 3how are you','>test3':'this is line 5who are you'}
I've imported the file but I'm unable to do it in this fashion. I want to delete the newline character at the end of each line so as to get one line. Spaces not required as seen. Any help would be appreciated
This is what I've tried so far
new_dict = {}
>>> db = open("/home/ak/Desktop/python_files/smalltext.txt")
for line in db:
if '>' in line:
new_dict[line]=''
else:
new_dict[line]=new_dict[line].append(line)