Coverage for e36_gematria_2.py : 57%

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
3"""Solution to chapter 7, exercise 36: gematria_equal_words"""
5from e35_gematria_1 import gematria_dict
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)
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]