|
|
|
|
|
by drallison
5895 days ago
|
|
Here's another way to do this in Python. lets = [chr(x) for x in range( ord('a'),ord('z')+1)]
def blankexpand( templates ):
expansion = []
for t in templates:
expansion = expansion + [t.replace('_',let,1) for let in lets]
return expansion
def expand( template ):
blanktiles = template.count('_')
if blanktiles == 0:
print 'nothing to expand'
elif blanktiles == 1:
print blankexpand( [template] )
elif blanktiles == 2:
print blankexpand( blankexpand( [template] ) )
else :
print 'too many blank tiles'
print
expand( 'abce' )
expand( 'a_')
expand( 'h_ll_')
expand( '___' )
|
|