Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'subject:Python': 0.05; 'ascii': 0.07; 'happily': 0.07; 'python': 0.08; 'correct.': 0.09; 'iterate': 0.09; 'readable': 0.09; '...,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'odd,': 0.16; 'okay,': 0.16; 'perhaps,': 0.16; 'printf': 0.16; 'py3': 0.16; 'wrote:': 0.18; 'simpler': 0.18; '(which': 0.19; 'programming': 0.20; 'suggest': 0.20; 'received:209.85.210.174': 0.21; 'received:mail- iy0-f174.google.com': 0.21; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; '(or': 0.22; 'indices': 0.23; 'suggests': 0.23; 'table.': 0.23; 'times,': 0.24; 'work.': 0.27; 'bit': 0.28; "i'm": 0.28; 'message-id:@mail.gmail.com': 0.29; 'example': 0.29; 'correct': 0.29; 'pm,': 0.29; 'fairly': 0.30; 'coding.': 0.30; 'object.': 0.30; 'returns,': 0.30; 'chris': 0.30; 'equivalent': 0.31; 'pretty': 0.31; 'thu,': 0.32; 'does': 0.32; 'list': 0.32; 'languages': 0.32; "isn't": 0.33; 'object': 0.33; 'points': 0.34; 'someone': 0.34; 'builds': 0.34; 'probably': 0.35; 'to:addr :python-list': 0.35; 'list.': 0.35; 'list,': 0.36; 'sequence': 0.37; 'but': 0.37; 'received:google.com': 0.37; "i'll": 0.38; 'received:209.85': 0.38; 'uses': 0.38; 'skip:\xa0 10': 0.39; 'received:209': 0.39; 'everyone': 0.39; 'being': 0.40; 'to:addr:python.org': 0.40; 'range': 0.61; 'simple': 0.61; 'your': 0.61; 'join': 0.61; '100': 0.70; "'for'": 0.84; 'querying': 0.84; 'ranks': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=q2VgFJYMTOWVCNa6h6YjXAlAgz0y6cZwYsbIYu4qdEs=; b=Y+NpOaPK9+Ky04OJgOya0i+hoc8bn9PUUHMiEu0kJALut9AJvrUDx+VKWDtWgaXDJ4 GMaltjRe5BTC303BTRl7iH3MFx2bVOgb8ROHM/EQctJ5swIzlXPg7GO8YTxH0mfRjjpK U4sVBpc72v4hp6/snbWn+3OYn63SLX4E9PrEcs6/1s1j8yUM2CAuyVtFWfbKxqS4Fylo KBq8FFhoTqE1qEuWexOIYTepbyWQyuwTu5/5Na6M+xJSJR2H9GDw4QE2KmQDEo/OdkU/ Nz02L0aKQqSMzm+r45hTrCJUNct4OegSyawJMG8Z+q+7Vp8Hj73wjPqalmPI60L/DQh5 NEQA== MIME-Version: 1.0 In-Reply-To: <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> Date: Thu, 15 Mar 2012 22:47:49 +1100 Subject: Re: Python is readable 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331812073 news.xs4all.nl 6940 [2001:888:2000:d::a6]:46085 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21655 On Thu, Mar 15, 2012 at 10:27 PM, Kiuhnm wrote: > On 3/15/2012 11:50, Chris Angelico wrote: >> I'll do a list comp, because they lend themselves well to one-liners. >> what_am_i =3D '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) > > > A few conjectures: > 1) '\n' is an object and join one of its methods; > 2) [...] is a list comprehension; > 3) that 'for' suggests that range isn't (or doesn't return) a list but an > iterator; > 4) points 2 and 3 suggest that [...] builds a list (or array?) by queryin= g > an iterator. > 5) "%X\t%"(i,i) is probably equivalent to the C-like Perl's > =A0sprintf("%X\t%c", i, i) > > So what_am_i is a simple ASCII table. Correct. Actually, there's a few differences between Python 2 and 3; in Py2, range() returns a list, but in Py3 an iterable object. But 'for' will happily iterate over a list. >> Okay, that one also uses printf formatting, which may be a smidge >> obscure. Here's a simpler example: >> >> what_am_i =3D [x*x for x in range(11)] > > what_am_i =3D 0, 1, 4, 9, ..., 100 Correct again. > Your first example suggests that range(n) is a sequence iterator which > returns, if queried n times, > =A00,...,n-1 > (which is a bit counterintuitive, IMHO). It's a little odd, perhaps, if seen in a vacuum. But everything counts from zero - list indices, etc - so it makes sense for range(len(lst)) to return indices valid for lst. List comps are pretty readable if you know how programming languages work. Python need not be readable by everyone and his grandmother, and it does a fairly good job of being grokkable to someone who has a few ranks in Coding. (Yeah, I'm a D&D nerd. ) ChrisA