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


Groups > comp.lang.python > #91751

Re: Where is 'palindrome' defined?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; "subject:' ": 0.07; 'nameerror:': 0.09; 'spelled': 0.09; 'spelling': 0.09; 'python': 0.11; 'def': 0.14; 'compares': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reversed': 0.16; 'wrote:': 0.16; 'string': 0.17; 'thanks,': 0.19; '>>>': 0.20; '"",': 0.22; '31,': 0.22; 'correctly.': 0.22; 'defined': 0.23; '2015': 0.23; 'header :In-Reply-To:1': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; 'checking': 0.27; 'behaving': 0.29; 'online:': 0.29; 'correct': 0.29; 'function': 0.30; "skip:' 10": 0.30; 'realize': 0.32; 'received:84': 0.32; 'traceback': 0.33; 'word.': 0.33; 'subject:?': 0.34; 'file': 0.34; 'gives': 0.35; 'to:addr :python-list': 0.35; 'false': 0.35; 'expected': 0.35; 'so,': 0.37; 'hi,': 0.37; 'subject:: ': 0.37; 'thought': 0.37; 'test': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.40; 'why': 0.40; 'show': 0.62; 'reverse': 0.66; 'special': 0.72; 'clearer': 0.84; 'subject:Where': 0.84; 'utc-7,': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=OoyysHLt c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=QrohdLjRRo4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=w1kyvF3s1A3NS96K4KYA:9 a=hkRvd_qDbHSOrj3Q:21 a=aKmk4-KNvzSkyudE:21 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
Date Tue, 02 Jun 2015 02:10:54 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Where is 'palindrome' defined?
References <83a279a3-133d-4a50-9af3-054233bcc6af@googlegroups.com> <888b51eb-0ede-4120-a914-aeec45d6366d@googlegroups.com>
In-Reply-To <888b51eb-0ede-4120-a914-aeec45d6366d@googlegroups.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.30.1433207459.13271.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433207459 news.xs4all.nl 2841 [2001:888:2000:d::a6]:53739
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91751

Show key headers only | View raw


On 2015-06-02 01:55, fl wrote:
> On Sunday, May 31, 2015 at 9:46:56 PM UTC-7, fl wrote:
>> Hi,
>>
>> When I search solution of reverse a string/number, I came across a short
>> function online:
>>
>> >>> def palindrome(num):
>> 	return str(num) == str(num)[::-1]
>>
>> I thought that it is a general function. And with the following variable:
>>
>> >>> a
>> '1234_5555'
>>
>> >>> parlindrome(a)
>>
>> Traceback (most recent call last):
>>   File "<pyshell#126>", line 1, in <module>
>>     parlindrome(a)
>> NameError: name 'parlindrome' is not defined
>>
>>
>> Then, I find that parlindrome is a special checking mirrored word.
>> I use Python 2.7.9. Why does the error message show
>>
>> name 'parlindrome' is not defined
>>
>>
>>
>> Thanks,
>
> Thanks, I realize that it was spelled wrong. Now, with the correct spelling
> the result is a 'False'. I have expected it gives reversed string. Is the
> function behaves correct or not?
>
>
It compares 'num' as a string to the reverse of that to test whether 
it's a palindrome,
so, yes, it's behaving correctly.

Perhaps its purpose would have been clearer if it had been called
"is_palindrome".

>
>>>> a='1234'
>>>> def palindrome(num):
> 	return str(num) == str(num)[::-1]
>>>> palindrome(a)
> False
>>>> palindrome("fread")
> False
>

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


Thread

Where is 'palindrome' defined? fl <rxjwg98@gmail.com> - 2015-05-31 21:46 -0700
  Re: Where is 'palindrome' defined? Gary Herron <gherron@digipen.edu> - 2015-05-31 23:55 -0700
    Re: Where is 'palindrome' defined? Grant Edwards <invalid@invalid.invalid> - 2015-06-01 15:02 +0000
  Re: Where is 'palindrome' defined? Larry Hudson <orgnut@yahoo.com> - 2015-05-31 23:56 -0700
  Re: Where is 'palindrome' defined? David Palao <dpalao.python@gmail.com> - 2015-06-01 08:58 +0200
    Re: Where is 'palindrome' defined? Marko Rauhamaa <marko@pacujo.net> - 2015-06-01 12:21 +0300
      Re: Where is 'palindrome' defined? David Palao <dpalao.python@gmail.com> - 2015-06-01 11:41 +0200
      Re: Where is 'palindrome' defined? John Ladasky <john_ladasky@sbcglobal.net> - 2015-06-02 14:14 -0700
        Re: Where is 'palindrome' defined? Marko Rauhamaa <marko@pacujo.net> - 2015-06-03 01:30 +0300
  Re: Where is 'palindrome' defined? Omar Abou Mrad <omar.aboumrad@gmail.com> - 2015-06-01 10:00 +0300
  Re: Where is 'palindrome' defined? Denis McMahon <denismfmcmahon@gmail.com> - 2015-06-01 15:17 +0000
  Re: Where is 'palindrome' defined? fl <rxjwg98@gmail.com> - 2015-06-01 17:55 -0700
    Re: Where is 'palindrome' defined? sohcahtoa82@gmail.com - 2015-06-01 18:07 -0700
    Re: Where is 'palindrome' defined? MRAB <python@mrabarnett.plus.com> - 2015-06-02 02:10 +0100

csiph-web