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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'first:': 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; 'stored': 0.13; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'titlecased': 0.16; 'wrote:': 0.16; 'stuff': 0.22; 'variable': 0.24; "i'm": 0.27; 'loop': 0.28; 'lines': 0.30; 'from:addr:web.de': 0.30; 'logic': 0.30; 'expression': 0.32; 'word.': 0.32; 'to:addr:python-list': 0.33; 'flag': 0.34; 'header:X-Complaints-To:1': 0.35; 'assuming': 0.37; 'checks': 0.37; 'put': 0.37; 'but': 0.37; 'received:org': 0.38; 'some': 0.38; 'subject:: ': 0.39; 'help': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'skip:n 30': 0.62; 'here': 0.65; 'here.': 0.66; 'special': 0.67; 'evaluate': 0.71; 'treatment': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Doctest failing Followup-To: gmane.comp.python.general Date: Sat, 10 Sep 2011 13:47:04 +0200 Organization: None References: <678b89fd-82f4-4080-8b36-e4d0ba30cdbf@o9g2000vbo.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084ac98.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315655225 news.xs4all.nl 2419 [2001:888:2000:d::a6]:40982 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13066 Tigerstyle wrote: > I'm strugglin with some homework stuff and am hoping you can help me > out here. > > This is the code: > > small_words = ('into', 'the', 'a', 'of', 'at', 'in', 'for', 'on') > new_title = [] > title_split = title.strip().lower().split() > for word in title_split: > if title_split[0] in small_words: > new_title.append(word.title()) > elif word in small_words: > new_title.append(word.lower()) > else: > new_title.append(word.title()) The logic of the for-loop is flawed; the expression title_split[0] in small_words will always evaluate to True if the first word is a "small word", even when the loop is already past the first word. You can work around that with a flag along these lines first = True for word in title_split: if first: # special treatment for the first word first = False else: # put checks for all words but the first here new_title.append(fixed_word) # assuming you have stored the titlecased # or lowercased word in the fixed_word # variable