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


Groups > comp.lang.python > #17085

Re: Verbose and flexible args and kwargs syntax

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder7.xlned.com!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'linear': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'type,': 0.07; 'worse': 0.07; '>>>>': 0.09; 'iterate': 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; 'constructs': 0.16; 'contrary,': 0.16; 'head,': 0.16; 'iterator': 0.16; 'reedy': 0.16; 'sequence.': 0.16; 'subject:syntax': 0.16; 'verbose,': 0.16; 'syntax': 0.16; 'language': 0.17; 'wrote:': 0.18; 'jan': 0.19; 'stuff': 0.22; 'header:In-Reply-To:1': 0.22; 'once.': 0.23; 'referring': 0.23; 'ignore': 0.26; 'suggestion': 0.26; 'constant': 0.29; 'pm,': 0.29; 'topic': 0.30; 'operation.': 0.30; 'pattern': 0.30; 'tail': 0.30; 'whats': 0.30; 'quite': 0.32; 'does': 0.32; 'values': 0.32; 'cases': 0.32; 'list': 0.32; 'objects': 0.32; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'list.': 0.35; 'copying': 0.35; 'something': 0.35; 'apply': 0.35; 'question': 0.36; 'pull': 0.37; 'but': 0.37; 'list,': 0.37; 'another': 0.37; 'think': 0.37; 'linked': 0.38; 'received:org': 0.38; 'should': 0.39; 'else': 0.39; 'to:addr:python.org': 0.40; 'more': 0.61; 'type': 0.61; 'design': 0.61; 'your': 0.61; 'collect': 0.61; 'target': 0.63; 'view': 0.65; 'taking': 0.66; 'easily.': 0.67; 'genuine': 0.68; 'anything.': 0.71; 'serious': 0.78; '12:12': 0.84; 'needed:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Verbose and flexible args and kwargs syntax
Date Mon, 12 Dec 2011 16:58:33 -0500
References <4EE5C576.2000307@gmail.com> <mailman.3550.1323705162.27778.python-list@python.org> <e31c5737-5514-4031-acdd-4882fe11b867@y7g2000vbe.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <e31c5737-5514-4031-acdd-4882fe11b867@y7g2000vbe.googlegroups.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.3571.1323727128.27778.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323727128 news.xs4all.nl 6877 [2001:888:2000:d::a6]:49170
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17085

Show key headers only | View raw


On 12/12/2011 12:12 PM, Eelco wrote:

> Im not sure if this is a genuine understanding, or trollish
> obtuseness.

If you are referring to what I write, it is based on genuine 
understanding of Python.

> Yes, the target can be anywhere in the sequence. And yes, the
> resulting list can contain objects of any type, so its very flexible
> in that regard too.
>
> But to relate it to the topic of this thread: no, the syntax does not
> allow one to select the type of the resulting sequence. It always
> constructs a list.

One use case of *target is to ignore the stuff collected in the target 
because one only wants a few end values from the iterable. Another is to 
pull stuff out because one wants to iterate through the rest. For both 
uses, a list is as good as anything.

> Yes, we can cast the list to be whatever we want on the next line,

Convert. For the very few cases one wants to do this, it is quite adequate.

 > but the question is whether this language design can be improved upon.

Not easily.

> The choice of a list feels arbitrary,

On the contrary, a list is precisely what is needed to collect an 
indefinite number of leftovers.

 > adding another line to cast it to
> something else would be even more verbose, and whats more, there would
> be serious performance implications if one should seek to apply this
> pattern to a deque/linkedlist; it would make taking off the head/tail
> of the list from a constant to a linear operation.

For a linked list, no *target and no copying is needed:

head, tail = llist

>>>> head, deque(tail) = somedeque
>
> Is better in every way I can think of (readability, consistence,
> performance) than:

>>>> head, *tail = somedeque
>>>> tail = deque(tail)

But your suggestion is much worse in each way than

head = somedeque.popleft()

To repeat, there is no reason to copy even once. If one does not want to 
mutate the deque, then one mutates an iterator view of the deque.

-- 
Terry Jan Reedy

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


Thread

Re: Verbose and flexible args and kwargs syntax Terry Reedy <tjreedy@udel.edu> - 2011-12-12 10:52 -0500
  Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-12 09:12 -0800
    Re: Verbose and flexible args and kwargs syntax Terry Reedy <tjreedy@udel.edu> - 2011-12-12 16:58 -0500
      Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-12 15:40 -0800
        Re: Verbose and flexible args and kwargs syntax Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-12 18:41 -0700
          Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 00:44 -0800
            Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 01:26 -0800
            Re: Verbose and flexible args and kwargs syntax Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-13 11:15 -0700
              Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 12:32 -0800
      Re: Verbose and flexible args and kwargs syntax Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-13 01:34 +0000
    Re: Verbose and flexible args and kwargs syntax alex23 <wuwei23@gmail.com> - 2011-12-12 16:27 -0800
      Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 00:30 -0800
        Re: Verbose and flexible args and kwargs syntax Cameron Simpson <cs@zip.com.au> - 2011-12-14 06:11 +1100
          Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 12:14 -0800

csiph-web