Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.01; 'ascii': 0.07; 'subject:code': 0.07; 'python': 0.08; '(int': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; '(lambda': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'other)': 0.16; 'versus': 0.16; 'wrote:': 0.18; 'string,': 0.18; '(which': 0.19; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.25; 'function': 0.27; 'fact': 0.27; '(and': 0.28; 'message-id:@mail.gmail.com': 0.28; 'subject:?': 0.31; 'value.': 0.32; 'list': 0.32; 'actual': 0.32; 'fri,': 0.34; 'to:addr:python-list': 0.34; 'probably': 0.34; 'integer': 0.34; 'received:google.com': 0.37; 'steven': 0.38; 'received:209.85': 0.38; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'double': 0.61; 'happen': 0.61; 'instantly': 0.67; 'heart': 0.68; 'size.': 0.71; 'clearer': 0.84; 'subject:hack': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=EAH24q9pss5fV8jfy2FfjB0JKPfDkfHQCMCop9WAImo=; b=CDEBu/D2rXwEVTq+ICd8/0t00umy5IQ5lVcxwfKrkJoMAPa9rg4CWxaPq1ZH+vbKa4 UD+QQKHpWpsuSGVIWLcvVXVHccMPfwPVkhQATqYgOzIizF9iihoSTnCw3xpxOJaRvG6G RtF36kHGQMLQMSkjsarnBVsdA9PODKgnCdQF8= MIME-Version: 1.0 In-Reply-To: <4ed818bb$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <4ed818bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 2 Dec 2011 13:07:57 +1100 Subject: Re: Clever hack or code abomination? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1322791680 news.xs4all.nl 6911 [2001:888:2000:d::a6]:41906 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16519 On Fri, Dec 2, 2011 at 11:15 AM, Steven D'Aprano wrote: > Try this on for size. > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0f =3D type(q)(c[c.index(chr(45))+1:])+type= (q)(1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0c =3D str.join('\n', list(map(chr, (45, 48= ))) + [c])[::2] > =A0 =A0 =A0 =A0 =A0 =A0c =3D (lambda a,b: a+b)(c[:c.index(chr(45))+1], ty= pe(c)(f)) I would consider integer representations of ASCII to be code smell. It's not instantly obvious that 45 means '-', even if you happen to know the ASCII table by heart (which most people won't). This is one thing that I like about C's quote handling; double quotes for a string, or single quotes for an integer with that character's value. It's clearer than the Python (and other) requirement to have an actual function call: for (int i=3D0;i<10;++i) { digit[i]=3D'0'+i; letter[i]=3D'A'+i; } versus for i in range(10): digit[i]=3Dchr(ord('0')+i) letter[i]=3Dchr(ord('A')+i) Ignoring the fact that you'd probably use a list comp in Python, this is imho a win for C. ChrisA