[Tutor] question on Partition

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed Dec 11 02:21:02 2002


On Wed, 11 Dec 2002, sachin mehra wrote:

> I need to use the partition function.  How can I use it?  Do I have to
> include any module for that?
>
> ###
> >>>paritition("attackatdawn")
> [['at', 'tack', 'at', 'dawn'],
> ['attack', 'at', 'dawn']]
>
> >>>partition("iscreamforicecream")
> [['is', 'cream', 'for', 'ice', 'cream'],
> ['i', 'scream', 'for', 'ice', 'cream']]
>
> >>>partition("uselesspython")
> [['use', 'less', 'python'],
> ['useless', 'python']]
>
> >>>partition("inaholetherelivedahobbit")
> [['in', 'a', 'hole', 'the', 're', 'lived', 'a', 'hobbit'],
> ['in', 'a', 'hole', 'there', 'lived', 'a', 'hobbit']]
> ###

Hi Sachin,

It is not built in; it's something I cooked up a few weeks ago when I was
thinking about your program.  However, it is a part of your homework to
write source code; we cannot directly give you the code to do this task.



This task is not too difficult to do if you approach the partitioning
problem recursively.  If you solve the problem recursively, your solution
should come to around five lines of code.

As a concrete example, given the word "attackatdawn", you can recursively
solve for the partitioning of "tackatdawn", or you can recursively solve
for the partitioning of "atdawn".  Either way, if can attack these smaller
problems, then you can solve for the partitioning of "attackatdawn".