Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2 

3"""Solution to chapter 7, exercise 36: gematria_equal_words""" 

4 

5from e35_gematria_1 import gematria_dict 

6 

7 

8def gematria_for(word): 

9 """Function that calculates the gematria 

10for a given word, an argument passed as a string. 

11""" 

12 return sum(gematria_dict().get(one_char, 0) 

13 for one_char in word) 

14 

15 

16def gematria_equal_words(input_word): 

17 """Function that takes a string (word) as input, 

18and returns a list of strings (words) whose calculated 

19gematria is identical.""" 

20 our_score = gematria_for(input_word.lower()) 

21 return [one_word.strip() 

22 for one_word in open('/usr/share/dict/words') 

23 if gematria_for(one_word.lower()) == our_score]