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


Groups > comp.lang.python > #66259

Re: A curious bit of code...

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'oh,': 0.09; 'works.': 0.09; '~ethan~': 0.09; '11:59': 0.16; 'away!': 0.16; 'received:67.18.44': 0.16; 'string:': 0.16; 'subject:bit': 0.16; 'wrote:': 0.18; 'examples': 0.20; 'fit': 0.20; 'feb': 0.22; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'van': 0.27; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'code': 0.31; 'that.': 0.31; 'really,': 0.31; 'fri,': 0.33; 'trouble': 0.34; 'but': 0.35; '14,': 0.36; 'edge': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:a 30': 0.61; 'skip:t 30': 0.61; 'received:173': 0.61; 'save': 0.62; 'saw': 0.77; 'ware': 0.91
Date Thu, 13 Feb 2014 13:33:47 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: A curious bit of code...
References <4cc09129-43ee-4205-a24c-03f92b594abc@googlegroups.com> <CAKJDb-OoN2K4--AseaFkuXv3-4vr+a3TPQc7omSrsHVYKcbBrw@mail.gmail.com> <ldjbft$af$1@ger.gmane.org> <CAPTjJmpi5HsKgAW7axTbNY5_3XeZqeeH4CsATz_6Rf0_2MgAMw@mail.gmail.com>
In-Reply-To <CAPTjJmpi5HsKgAW7axTbNY5_3XeZqeeH4CsATz_6Rf0_2MgAMw@mail.gmail.com>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator3304.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source-IP 173.12.184.233
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.233]) [173.12.184.233]:35283
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20=
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 <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.6894.1392328506.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392328506 news.xs4all.nl 2900 [2001:888:2000:d::a6]:33153
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66259

Show key headers only | View raw


On 02/13/2014 01:01 PM, Chris Angelico wrote:
> On Fri, Feb 14, 2014 at 7:55 AM, Emile van Sebille <emile@fenx.com> wrote:
>> On 2/13/2014 11:59 AM, Zachary Ware wrote:
>>>
>>> In a fit of curiosity, I did some timings:
>>
>>
>> Snip of lots of TMTOWTDT/TIMTOWTDI/whatever... timed examples :)
>>
>> But I didn't see this one:
>>
>> s[::len(s)-1]
>
> .... AAAAAAAAAAAAAAAAAAARGGGGGGGGGGHHHH!
>
> Really, I actually did pause, double-take, and then scream under my
> breath, when I saw that. Yes, it works. But please, if you EVER do
> this, save me the trouble and just submit your code to thedailywtf.com
> straight away!

Oh, it's not that bad!  All you have to do is handle the edge case of an empty string:

s[::len(s)-1 if s else True]

*ducks and runs*

--
~Ethan~

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


Thread

A curious bit of code... forman.simon@gmail.com - 2014-02-13 10:37 -0800
  Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-13 13:45 -0500
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 10:45 -0800
  Re: A curious bit of code... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-13 19:09 +0000
  Re: A curious bit of code... Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-02-13 20:05 +0100
  Re: A curious bit of code... Neil Cerutti <neilc@norwich.edu> - 2014-02-13 19:17 +0000
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 11:20 -0800
    Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-13 14:28 -0500
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 11:25 -0800
  Re: A curious bit of code... Neil Cerutti <neilc@norwich.edu> - 2014-02-13 19:25 +0000
  Re: A curious bit of code... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-13 19:32 +0000
  Re: A curious bit of code... Peter Otten <__peter__@web.de> - 2014-02-13 20:43 +0100
    Re: A curious bit of code... Marko Rauhamaa <marko@pacujo.net> - 2014-02-13 21:56 +0200
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 11:23 -0800
  Re: A curious bit of code... Neil Cerutti <neilc@norwich.edu> - 2014-02-13 19:51 +0000
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 11:59 -0800
  Re: A curious bit of code... Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-13 13:59 -0600
  Re: A curious bit of code... Chris Angelico <rosuav@gmail.com> - 2014-02-14 07:29 +1100
  Re: A curious bit of code... Tim Chase <python.list@tim.thechases.com> - 2014-02-13 14:39 -0600
  Re: A curious bit of code... Emile van Sebille <emile@fenx.com> - 2014-02-13 12:55 -0800
    Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-13 16:24 -0500
      Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 16:23 -0800
  Re: A curious bit of code... Chris Angelico <rosuav@gmail.com> - 2014-02-14 08:01 +1100
  Re: A curious bit of code... Neil Cerutti <neilc@norwich.edu> - 2014-02-13 21:01 +0000
  Re: A curious bit of code... Peter Otten <__peter__@web.de> - 2014-02-13 22:06 +0100
  Re: A curious bit of code... Chris Angelico <rosuav@gmail.com> - 2014-02-14 08:10 +1100
  Re: A curious bit of code... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-13 21:14 +0000
  Re: A curious bit of code... Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-13 15:20 -0600
  Re: A curious bit of code... Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-13 15:19 -0600
  Re: A curious bit of code... Emile van Sebille <emile@fenx.com> - 2014-02-13 13:23 -0800
  Re: A curious bit of code... Chris Angelico <rosuav@gmail.com> - 2014-02-14 08:31 +1100
    Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-13 16:38 -0500
  Re: A curious bit of code... Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-13 15:47 -0600
  Re: A curious bit of code... Serhiy Storchaka <storchaka@gmail.com> - 2014-02-13 23:49 +0200
    Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-13 16:51 -0500
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 13:33 -0800
  Re: A curious bit of code... Chris Angelico <rosuav@gmail.com> - 2014-02-14 09:13 +1100
  Re: A curious bit of code... Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 14:26 -0800
  Re: A curious bit of code... Terry Reedy <tjreedy@udel.edu> - 2014-02-13 19:29 -0500
  Re: A curious bit of code... forman.simon@gmail.com - 2014-02-13 18:45 -0800
    Re: A curious bit of code... Ned Batchelder <ned@nedbatchelder.com> - 2014-02-13 22:26 -0500
      Re: A curious bit of code... forman.simon@gmail.com - 2014-02-14 12:04 -0800
        Re: A curious bit of code... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-14 21:01 +0000
  Re: A curious bit of code... Dave Angel <davea@davea.name> - 2014-02-14 07:19 -0500
    Re: A curious bit of code... Roy Smith <roy@panix.com> - 2014-02-14 09:06 -0500

csiph-web