Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13117

Re: Doctest failing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'confuse': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.15; 'assignment.': 0.16; 'bieber': 0.16; 'case...': 0.16; 'declaimed': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'lowercase': 0.16; 'received:66.245': 0.16; 'received:dsl.mindspring.com': 0.16; 'received:mindspring.com': 0.16; 'received:wlfraed': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'weapon': 0.16; 'wulfraed': 0.16; 'language': 0.17; '>>>': 0.18; 'url:home': 0.21; 'sep': 0.23; 'lee': 0.28; 'sat,': 0.28; 'basically,': 0.30; 'construct': 0.30; '(including': 0.30; 'list': 0.32; 'mass': 0.32; 'word.': 0.32; 'to:addr:python-list': 0.33; 'done': 0.34; 'header:X-Complaints-To:1': 0.35; 'anything': 0.36; 'charset:us- ascii': 0.36; 'doing': 0.36; 'skip:" 10': 0.36; 'received:org': 0.38; 'some': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'else': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.39; 'stop': 0.61; 'lower': 0.64; 'taking': 0.66; 'account': 0.66; 'taught': 0.71; 'dennis': 0.77; 'justifying': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Doctest failing
Date Sat, 10 Sep 2011 23:18:21 -0700
Organization > Bestiaria Support Staff <
References <678b89fd-82f4-4080-8b36-e4d0ba30cdbf@o9g2000vbo.googlegroups.com> <j4grlj$dg2$1@dough.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host user-11fa4e5.dsl.mindspring.com
X-Newsreader Forte Agent 3.3/32.846
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.972.1315721914.27778.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315721914 news.xs4all.nl 2537 [2001:888:2000:d::a6]:49832
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:13117

Show key headers only | View raw


On Sat, 10 Sep 2011 16:25:42 -0700, Dennis Lee Bieber
<wlfraed@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
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-10 04:20 -0700
  Re: Doctest failing Mel <mwilson@the-wire.com> - 2011-09-10 07:43 -0400
    Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 09:36 -0700
  Re: Doctest failing Peter Otten <__peter__@web.de> - 2011-09-10 13:47 +0200
    Re: Doctest failing ting@thsu.org - 2011-09-10 19:12 -0700
      Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 09:42 -0700
  Re: Doctest failing Thomas Jollans <t@jollybox.de> - 2011-09-10 13:50 +0200
    Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 09:39 -0700
  Re: Doctest failing Alister Ware <alister.ware@ntlworld.com> - 2011-09-10 12:24 +0000
    Re: Doctest failing Chris Angelico <rosuav@gmail.com> - 2011-09-11 01:56 +1000
      Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 09:40 -0700
    Re: Doctest failing Ethan Furman <ethan@stoneleaf.us> - 2011-09-11 11:43 -0700
    Re: Doctest failing Chris Angelico <rosuav@gmail.com> - 2011-09-12 11:03 +1000
      Re: Doctest failing Ben Finney <ben+python@benfinney.id.au> - 2011-09-12 11:37 +1000
        Re: Doctest failing Chris Angelico <rosuav@gmail.com> - 2011-09-12 13:06 +1000
          Re: Doctest failing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-12 14:29 +1000
  Re: Doctest failing Terry Reedy <tjreedy@udel.edu> - 2011-09-10 13:59 -0400
    Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 04:46 -0700
      Re: Doctest failing Terry Reedy <tjreedy@udel.edu> - 2011-09-11 13:03 -0400
  Re: Doctest failing Terry Reedy <tjreedy@udel.edu> - 2011-09-10 15:36 -0400
  Re: Doctest failing Peter Otten <__peter__@web.de> - 2011-09-10 22:49 +0200
  Re: Doctest failing Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-09-10 16:25 -0700
  Re: Doctest failing Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-09-10 23:18 -0700
    Re: Doctest failing Tigerstyle <laddosingh@gmail.com> - 2011-09-11 09:43 -0700
      Re: Doctest failing Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-09-11 12:37 -0700

csiph-web