mercredi 18 juin 2014

Python string format using map of arrays


Vote count:

0




I have a thesaurus (dictionary) of values:



words = {
'hot' : ['hot', 'scalding', 'warm'],
'cold' : ['cold', 'frigid', 'freezing'],
...}


And I would like to use this thesaurus to randomly format strings



'the water is {word.cold}'.format(word=words)


But this (as expected) is inserting the entire array into the string. Is there a way to pass a choice function to format or do I need to write my own custom format functionality including the word/key matching?



asked 32 secs ago






Aucun commentaire:

Enregistrer un commentaire