stoichiograph

Spell words with elemental symbols from the periodic table.
Log | Files | Refs | LICENSE

commit a87faf6d69b79304860811ffc966fc1c4f0af52d
parent 5beeab69ca702569af5bf5cc72a635aee4f9ed73
Author: Amin Mesbah <mesbah.amin@gmail.com>
Date:   Sun, 26 Feb 2017 12:27:44 -0800

Simplify list comprehension in `speller.spell()`.

Diffstat:
Mspeller.py | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/speller.py b/speller.py @@ -38,16 +38,15 @@ def spell(word, symbols=ELEMENTS): g = Graph() build_spelling_graph(word, g) - spellings = list() - for first in g.firsts(): - for last in g.lasts(): - for path in find_all_paths(g._children_of, first, last): - spellings.append(tuple(node.value for node in path)) - - elemental_spellings = sorted([ - tuple(token.capitalize() for token in spelling) - for spelling in spellings - ], reverse=True) + elemental_spellings = sorted( + [ + tuple(node.value.capitalize() for node in path) + for first in g.firsts() + for last in g.lasts() + for path in find_all_paths(g._children_of, first, last) + ], + reverse=True + ) log.info('Spellings: {}'.format(elemental_spellings))