Doctest failing

Tigerstyle laddosingh at gmail.com
Sun Sep 11 18:43:31 CEST 2011


On 11 Sep, 08:18, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Sat, 10 Sep 2011 16:25:42 -0700, Dennis Lee Bieber
> <wlfr... at ix.netcom.com> declaimed the following in
> gmane.comp.python.general:
>
>
>
> > in the language documentation... It will give you a simple way to know
> > if you are looking at the first word. Basically, you want to title-case
> > the word IF it is the first word OR the word is NOT in the list of
> > lowercase words; anything else goes through as lower case...
>
>         Of course, most of this can be done in a single line (including
> taking into account that some words may have a punctuation mark which
> would confuse the original).
>
> >>> smalls = ['into', 'the', 'a', 'of', 'at', 'in', 'for', 'on' ]
> >>> punct = ".,;:?!;'\"(){}[]"
> >>> def recase(str = "physicist odd-affection, or how i was taught to stop fretting and adore the weapon of mass destruction"):
>
> ...     return " ".join( w.title() if i == 0 or w.strip(punct) not in
> smalls else w
> ...                     for i,w in enumerate(str.lower().strip().split()) )
> ...>>> recase()
>
> 'Physicist Odd-Affection, Or How I Was Taught To Stop Fretting And Adore
> the Weapon of Mass Destruction'>>> recase("what? me worry?")
> 'What? Me Worry?'
> >>> recase("the end of the matter is, to be blunt, a confusion")
>
> 'The End of the Matter Is, To Be Blunt, a Confusion'>>> recase("the end of the matter is in, to be blunt, a confusion")
>
> 'The End of the Matter Is in, To Be Blunt, a Confusion'>>> smalls = ['into', 'the', 'a', 'of', 'at', 'in', 'for', 'on', "and", "is", "to" ]
> >>> recase()
>
> 'Physicist Odd-Affection, Or How I Was Taught To Stop Fretting and Adore
> the Weapon of Mass Destruction'>>> recase("the end of the matter is in, to be blunt, a confusion")
>
> 'The End of the Matter is in, to Be Blunt, a Confusion'
>
>
>
>         Of course, explaining what this construct is doing is the trick to
> justifying it for a homework assignment.
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr... at ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Too much destruction in this post man, and yeah I would not be able to
explain the code for my homework.



More information about the Python-list mailing list