stoichiograph

Spell words with elemental symbols from the periodic table.
git clone git://git.amin.space/stoichiograph.git
Log | Files | Refs | LICENSE

commit 1d9ca57e5cdfaa5cc1915b44032fe3d2f4017484
parent fc0bb55e80b07130fc9aa4062d473e5819810b72
Author: amin <dev@aminmesbah.com>
Date:   Sun, 26 Feb 2017 20:27:44 +0000

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

FossilOrigin-Name: 719340a9a89b1d6fee4cd7d4d891f2c66747e88ab9b03ab38fa7339632b13fab
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))