python - Find all upper, lower and mixed case combinations of a string -
i want write program take string, let's "fox"
, display:
fox, fox, fox, fox, fox, fox, fox, fox
my code far:
string = raw_input("enter string: ") length = len(string) in range(0, length): j in range(0, length): if == j: x = string.replace(string[i], string[i].upper()) print x
output far:
enter string: fox fox fox fox >>>
>>> import itertools >>> map(''.join, itertools.product(*((c.upper(), c.lower()) c in 'fox'))) ['fox', 'fox', 'fox', 'fox', 'fox', 'fox', 'fox', 'fox']
or
>>> s = 'fox' >>> map(''.join, itertools.product(*zip(s.upper(), s.lower())))
Comments
Post a Comment