[Tutor] Using for loops for combinations
Danny Yoo
dyoo at hashcollision.org
Wed Feb 19 03:56:24 CET 2014
On Tue, Feb 18, 2014 at 6:34 PM, Chinanu 'Chinex' Onyekachi
<chinex at live.com> wrote:
> Thanks for taking you time to explain.
>
> minus = ['subtract'] #creates a list for subtract
>
>
> for i in minus:
>
> minuslist1 = [i[0].upper() + i[1:]]
>
> minuslist2 = [i[0] + i[1].upper() + i[2:]]
>
> minuslist3 = [i[0:].upper()]
>
> minus.extend(minuslist1)
>
> minus.extend(minuslist2)
>
> minus.extend(minuslist3)
>
> print 'list is: %r' % (minus ,),
>
> I get this output ['subtract', 'Subtract', 'sUbtract', 'SUBTRACT']
> but I feel it is going to take ages to do it this way and get all the
> possible combinations. Would use another for loop be the only way to speed
> things up, and if so how? I’m clearly struggling at forming loops.
Please read:
http://www.catb.org/~esr/faqs/smart-questions.html#uselists
Also, if you have worked all night on this particular problem, as
mentioned in the Stack Overflow question you posted,
http://stackoverflow.com/questions/21856705/find-all-possible-combinations-of-a-specific-word-string-using-any-combination
then know that you are probably not in a good frame of mind for
understanding the problem. Take a break from it today, and talk to
your instructor the next day if you are still confused.
Also note that if you are trying to normalize input, it's usually the
case that you want to clean it up, rather than have to deal with it
with all its messiness. For example, if you're trying to read:
"uppercase"
or
"UpperCase"
or
"UPPERCASE"
or
...
in all its varieties in a uniform way, then just upper() the input.
Normalize it. That kind of data digestion makes case analysis easier
sometimes. Why do you think that computer systems use UPPERCASE
sometimes?
More information about the Tutor
mailing list