[Tutor] Using for loops for combinations

Chinanu 'Chinex' Onyekachi chinex at live.com
Tue Feb 18 17:37:29 CET 2014


Find all possible combinations of a specific word (string) using any combination of upper case and lower case letters with a for loop (no itertools). 



An example:

string_input = hat

comboination = ['hat', 'Hat', 'HAt', 'HAT', 'hAT', 'haT', 'HaT', 'hAt']



What I've tried so far, I’m trying to do this using knowledge from loops, if and else, strings and lists.
    gear = ['hat']

for i in range(len(gear[0])):
    gearlist1 = list(gear[0])
    gearlist2 = [c.upper() for c in gearlist1]
    gearlist3 = [gearlist1[0].join(gearlist2)]


print 'list is: %r' % (gearlist3 ,),
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140218/48575a11/attachment-0001.html>


More information about the Tutor mailing list