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


Groups > comp.lang.python > #48921

Re: Simple I/O problem can't get solved

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '21,': 0.07; 'canal': 0.09; 'cleanup': 0.09; 'function:': 0.09; 'newline': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; "wouldn't": 0.14; 'expecting': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'words.': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '(such': 0.24; 'subject:problem': 0.24; 'post': 0.26; 'subject:/': 0.26; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'leave': 0.29; 'code': 0.31; 'lines': 0.31; 'minor': 0.31; 'strip': 0.31; 'file': 0.32; 'fri,': 0.33; "i'd": 0.34; 'test': 0.35; 'but': 0.35; 'consist': 0.36; 'subject:Simple': 0.36; "didn't": 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'name': 0.63; 'occur': 0.65; 'combining': 0.68; 'subject:get': 0.81; 'detecting': 0.84; 'otten': 0.84; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Simple I/O problem can't get solved
Date Sat, 22 Jun 2013 12:11:45 +0200
Organization None
References <4785de5f-a84d-4417-9709-68bf2f4076e8@googlegroups.com> <kq15i6$80e$1@ger.gmane.org> <CAPTjJmoCTvXRMfU2aiZMM-6UiyHspbgRfMFSqHqr+Xm5nHUE1A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084bd63.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.3691.1371895849.3114.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371895849 news.xs4all.nl 15906 [2001:888:2000:d::a6]:57396
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48921

Show key headers only | View raw


Chris Angelico wrote:

> On Fri, Jun 21, 2013 at 7:15 PM, Peter Otten <__peter__@web.de> wrote:
>> Combining these modifications:
>>
>> for line in f:
>>     word = line.strip()
>>     if is_palindrome.is_palindrome(word):
>>         print word
> 
> Minor quibble: I wouldn't use the name 'word' here, unless you're
> expecting the file to consist of one-word lines (such as DICTOT.DIC
> from old PMMail). For detecting phrase/sentence palindromes, I'd keep
> the name 'line'.

Somehow it didn't occur to me that you might test anything but words.
However, if you want to check sentences (as some unused code in the original 
post suggests) I think you should not strip off the newline and leave the 
necessary cleanup to the test function:

>>> def is_palindrome(s):
...     t = "".join(c for c in s.casefold() if c.isalnum())
...     return t == t[::-1]
... 
>>> is_palindrome("A man, a plan, a canal - Panama!\n")
True

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


Thread

Simple I/O problem can't get solved nickgan.sps@windowslive.com - 2013-06-21 01:57 -0700
  Re: Simple I/O problem can't get solved Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-21 12:11 +0300
  Re: Simple I/O problem can't get solved Peter Otten <__peter__@web.de> - 2013-06-21 11:15 +0200
    Re: Simple I/O problem can't get solved nickgan.sps@windowslive.com - 2013-06-21 02:20 -0700
  Re: Simple I/O problem can't get solved Chris Angelico <rosuav@gmail.com> - 2013-06-22 19:07 +1000
  Re: Simple I/O problem can't get solved Peter Otten <__peter__@web.de> - 2013-06-22 12:11 +0200
  Re: Simple I/O problem can't get solved Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-22 12:58 -0400

csiph-web