fork(1) download
  1. # create an empty dictionary:
  2. my_dict = {}
  3.  
  4. ## open the file:
  5. #with open("file.fna") as file:
  6.  
  7. ## read the file line by line:
  8. #for line in file:
  9.  
  10. # to demonstrate it in ideone.com, we read from the standard input instead of a file
  11. for _ in range(4):
  12. line = input()
  13.  
  14. # split at whitespace and take the last word:
  15. word = line.split()[-1]
  16.  
  17. # add entry to dictionary: all but the last character -> key; last character -> value
  18. my_dict[word[:-1]] = word[-1]
  19.  
  20. print(my_dict)
Success #stdin #stdout 0.02s 9984KB
stdin
read 1 ATTCT
read 2 CATTC
read 3 CCTAT
read 4 AAACA

stdout
{'CATT': 'C', 'CCTA': 'T', 'AAAC': 'A', 'ATTC': 'T'}