fork download
  1. def add_to_letter_counts(d, s):
  2. '''(dict of {str: int}, str) -> NoneType
  3.  
  4. d is a dictionary where the keys are single-letter strings and the values
  5. are counts.
  6.  
  7. For each letter in s, add to that letter's count in d.
  8.  
  9. Precondition: all the letters in s are keys in d.
  10.  
  11. >>> letter_counts = {'i': 0, 'r': 5, 'e': 1}
  12. >>> add_to_letter_counts(letter_counts, 'eerie')
  13. >>> letter_counts
  14. {'i': 1, 'r': 6, 'e': 4}
  15. '''
  16.  
  17. for c in s:
  18. if c in letter_counts.keys() ==True:
  19. letter_counts[c] +=1
  20. letter_counts = {'i': 0, 'r': 5, 'e': 1}
  21. add_to_letter_counts(letter_counts, 'eerie')
  22. letter_counts
Success #stdin #stdout 0.01s 7084KB
stdin
Standard input is empty
stdout
Standard output is empty