Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17372
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'motivated': 0.05; 'currently,': 0.07; 'pypy': 0.07; 'tends': 0.07; 'type,': 0.07; 'python': 0.08; 'dynamically': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'successive': 0.09; 'subject:python': 0.10; 'read.': 0.10; 'intermediate': 0.15; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'identifiers.': 0.16; 'overrides': 0.16; 'preexisting': 0.16; 'subject:case': 0.16; 'vectors': 0.16; 'examples': 0.16; 'language': 0.17; 'interesting.': 0.18; 'wrap': 0.18; 'slightly': 0.19; 'this?': 0.19; 'primarily': 0.21; 'appropriate': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; "people's": 0.24; 'stefan': 0.24; 'code': 0.25; 'function': 0.27; 'skip:[ 10': 0.27; 'compare': 0.28; 'subject:" ': 0.28; '(you': 0.28; 'lists': 0.28; 'elements': 0.29; 'class': 0.29; 'lines': 0.30; 'keeps': 0.30; 'developers': 0.32; 'does': 0.32; 'done,': 0.32; 'implementing': 0.32; 'list': 0.32; 'pretty': 0.32; "isn't": 0.33; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'there': 0.33; 'done': 0.34; 'to:addr:python-list': 0.34; 'community': 0.34; 'discussed': 0.34; 'realize': 0.34; 'received:84': 0.34; 'certain': 0.34; 'options:': 0.34; 'surprised': 0.34; 'something': 0.35; 'subject:/': 0.35; 'subject:lists': 0.36; 'but': 0.37; 'list,': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'using': 0.38; 'received:org': 0.38; 'couple': 0.38; 'clearly': 0.39; 'to:addr:python.org': 0.40; 'hope': 0.61; 'more': 0.61; 'subject': 0.62; 'direction.': 0.64; 'movement': 0.64; 'stated': 0.68; 'informative': 0.73; 'analysis': 0.77; 'strategies': 0.82; 'habit': 0.84; 'nathan': 0.84; 'subject:Making': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Stefan Behnel <stefan_ml@behnel.de> |
| Subject | Re: Making the case for "typed" lists/iterators in python |
| Date | Fri, 16 Dec 2011 19:23:27 +0100 |
| References | <CAOFbRmL_w4QJaCdP8bo1YOi-u0i=SPtAcV51PsQOTytKhsJFVw@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | dslb-084-056-028-212.pools.arcor-ip.net |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Lightning/1.0b2 Thunderbird/3.1.15 |
| In-Reply-To | <CAOFbRmL_w4QJaCdP8bo1YOi-u0i=SPtAcV51PsQOTytKhsJFVw@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.3744.1324059823.27778.python-list@python.org> (permalink) |
| Lines | 56 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324059823 news.xs4all.nl 6914 [2001:888:2000:d::a6]:51198 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17372 |
Show key headers only | View raw
Nathan Rice, 16.12.2011 18:48: > I realize this has been discussed in the past, I hope that I am > presenting a slightly different take on the subject that will prove > interesting. This is primarily motivated by my annoyance with using > comprehensions in certain circumstances. > > Currently, if you want to perform successive transformations on the > elements of a list, a couple of options: > > 1. Successive comprehensions: > > L2 = [X(e) for e in L1] > L3 = [Y(e) for e in L2] > L4 = [Z(e) for e in L3] > or > L2 = [e.X() for e in L1] > > This gets the job done and gives you access to all the intermediate > values, but isn't very succinct, particularly if you are in the habit > of using informative identifiers. > > 2. One comprehension: > > L2 = [Z(X(Y(e))) for e in L1] > or > L2 = [e.X().Y().Z() for e in L1] > > This gets the job done, but doesn't give you access to all the > intermediate values, and tends to be pretty awful to read. > > Having "typed" lists let you take preexisting string/int/etc methods > and expose them in a vectorized context and provides an easy way for > developers to support both vectors and scalars in a single function > (you could easily "fix" other people's functions dynamically to > support both). Additionally, "typed" lists/iterators will allow > improved code analysis and optimization. The PyPy people have already > stated that they are working on implementing different strategies for > lists composed of a single type, so clearly there is already community > movement in this direction. > > Just compare the above examples to their type-aware counterparts: > > L2 = X(L1) > L2 = L1.X() > > L2 = Z(Y(X(L1))) > L2 = L1.X().Y().Z() What keeps you from implementing this? You don't need to change the language for it, just wrap the list in a class that overrides __getattr__() to return something that does the appropriate transformation for each element. I would be surprised if you needed more than a couple of lines of Python code for that. Stefan
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Making the case for "typed" lists/iterators in python Stefan Behnel <stefan_ml@behnel.de> - 2011-12-16 19:23 +0100
csiph-web