[Tutor] Using for loops for combinations

Danny Yoo dyoo at hashcollision.org
Wed Feb 19 03:14:45 CET 2014


On Tue, Feb 18, 2014 at 5:15 PM, Chinanu 'Chinex' Onyekachi
<chinex at live.com> wrote:
> I’m having difficulties uppercasing a single portion (e.g. hAt) and two
> portions (e.g. HaT) of the string.


[Adding tutor at python.org to CC.  Please use reply-to-all in future
emails on this list.  Thanks!]


Hi Chinanu,


There is a crucial key to this problem.  You must work with a _simpler
problem_ and a _partial solution_, and keeping it up to date as you
learn more and more about the problem and solution.


What does a "simpler problem" mean here?  What does a "partial solution" mean?



Let's take the case where we're trying to compute the combinations for "hat".

Let's call this C("hat").  From your problem statement about, we know
what C("hat") looks like.



Here's a  subquestion of C("hat"): what are the combinations for "h"?

That is, what do we know about C("h")?

    C("h")   -->   ["h", "H"]

Trivial case, but worth thinking about.




Here's another subquestion of C("hat"): what are the combinations for "ha"?

That is, what do we know about C("ha")?

    C("ha")   -->   ["ha", "Ha", "hA", "HA"]

This we know without having to do any coding.



But it's worth thinking: can we get C("ha") easily out of C("h")?

Yes.

Just take the results of C("h"), and put "a" or "A" at the end of each.

    C("h")   -->   ["h", "H"]
    C("ha")   -->  ["ha", "hA",
                        "Ha", "HA"]




Here's another subquestion of C("hat"): what are the combinations for "hat"?

But it's worth thinking: can we get C("hat") easily out of C("ha")?

Yes.




Hopefully that sketches out what I think is the intent of this problem.


More information about the Tutor mailing list