I'm trying to make a function which returns a dictionary that has three keys called "first" "second" and "third". These keys all have a sequence of letters as their values. I wrote the key-value pairs down in a file that I called sequences.txt. So, they're seperated from my script. Moreover, the keys are separated from their values with a space. (So, in my function I tried to split the lines.) The issue is that when I try to read the file in my function it doesn't seem to work. Can anyone maybe see where it goes wrong?
first AGGCGAA
second TTTCGG
third GCGCGAA
def data(name):
input_file = open(name)
file_content = input_file.read()
di = {}
for line in input_file:
fields = line.split()
read_name = fields[0]
read_seq = fields[1]
di[read_name].append(read_seq)
return di
input_file.close()
print(data('sequences.txt'))
fields = line.split(' ')split()default value is the the same assplit(' ')