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