def allstrings(alphabet): yield '' for astring in allstrings(alphabet): for letter in alphabet: yield astring + letter