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


Groups > comp.lang.python > #84614

Re: Why does argparse return None instead of [] if an append action isn't used?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
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; 'python3': 0.07; '2000,': 0.09; 'lawrence': 0.09; 'objects,': 0.09; 'subject:None': 0.09; 'subject:Why': 0.09; 'jan': 0.12; '10000000': 0.16; '100000000': 0.16; '323': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'creating': 0.23; 'mon,': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'though.': 0.31; 'time:': 0.31; 'tuples': 0.31; 'probably': 0.32; 'anybody': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'confirm': 0.64; '10000': 0.68; '26,': 0.68; '2015': 0.84; 'us?': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=D2yZjYKCJUS5tkbRoE/IhETX2zx1yz/MYn7tfIZnlGs=; b=BE9O3OwtuJPTp9nrzZEjDS8EqqxCUE/EDMEG6k4Zr9MsNXxWipgr2nyd8Msb3FkXfn bds6QujFo1zI43P9hXD1JVxey3UGQfIPVnwUl08bibuq98J3tb2izJYPFPqIQEYEp53K cNnZ4ce/CgXL0TArjUiAr/kZF9uqtATI6no8mkq5FBpwMiM7sNG/oB/az18WyvvYwdvJ o+b4X9XH1+I43xM0gqvX2ksHuHlRYoB5BJP2S4bxny3iKQzZ1whuUSRfwkt/x7urpTTx SXvVBl35lEQPen499MXCpsfbWW26UkHx0XcYgsfsSFtsY4zPLZiGkUfUQokUOKO3qpCH RcRg==
X-Received by 10.66.153.48 with SMTP id vd16mr36176176pab.146.1422296655802; Mon, 26 Jan 2015 10:24:15 -0800 (PST)
MIME-Version 1.0
In-Reply-To <ma5ssj$ars$1@ger.gmane.org>
References <l265obxc6d.ln2@news.ducksburg.com> <mailman.17529.1420816664.18130.python-list@python.org> <8tshpbxjvv.ln2@news.ducksburg.com> <mailman.18148.1422281105.18130.python-list@python.org> <ta4ipbx9j3.ln2@news.ducksburg.com> <mailman.18151.1422288861.18130.python-list@python.org> <qotioft4iao.fsf@ruuvi.it.helsinki.fi> <ma5ssj$ars$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 26 Jan 2015 11:23:34 -0700
Subject Re: Why does argparse return None instead of [] if an append action isn't used?
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.18155.1422296665.18130.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422296665 news.xs4all.nl 2949 [2001:888:2000:d::a6]:41228
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84614

Show key headers only | View raw


On Mon, Jan 26, 2015 at 10:18 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> IIRC, and probably from this list, creating tuples is way faster than
> creating lists, but accessing items is slower.  Can anybody confirm this for
> us?

The first seems to be true as long as the tuples are small.

$ python3 -m timeit 't = (1000, 2000, 3000)'
100000000 loops, best of 3: 0.0147 usec per loop
$ python3 -m timeit 't = [1000, 2000, 3000]'
10000000 loops, best of 3: 0.0678 usec per loop
$ python3 -m timeit 't = tuple(range(10000))'
10000 loops, best of 3: 183 usec per loop
$ python3 -m timeit 't = list(range(10000))'
10000 loops, best of 3: 174 usec per loop
$ python3 -m timeit 't = tuple(range(10000000))'
10 loops, best of 3: 323 msec per loop
$ python3 -m timeit 't = list(range(10000000))'
10 loops, best of 3: 306 msec per loop

This is probably a result of the use of freelists to avoid
reallocating the tuple objects, though. I don't see any substantial
difference in access time:

$ python3 -m timeit -s 't = tuple(range(10000))' 't[5000]'
10000000 loops, best of 3: 0.0316 usec per loop
$ python3 -m timeit -s 't = list(range(10000))' 't[5000]'
10000000 loops, best of 3: 0.0318 usec per loop
$ python3 -m timeit -s 't = tuple(range(10000))' 'for x in t: pass'
10000 loops, best of 3: 112 usec per loop
$ python3 -m timeit -s 't = list(range(10000))' 'for x in t: pass'
10000 loops, best of 3: 113 usec per loop

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


Thread

Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 14:44 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Skip Montanaro <skip.montanaro@gmail.com> - 2015-01-09 08:57 -0600
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 15:25 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Ned Batchelder <ned@nedbatchelder.com> - 2015-01-09 10:12 -0500
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000
      Re: Why does argparse return None instead of [] if an append action isn't used? Peter Otten <__peter__@web.de> - 2015-01-26 15:04 +0100
        Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 15:50 +0000
          Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 09:13 -0700
            Re: Why does argparse return None instead of [] if an append action isn't used? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-26 18:29 +0200
              Re: Why does argparse return None instead of [] if an append action isn't used? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-26 17:18 +0000
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:23 -0700
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:26 -0700
  Re: Why does argparse return None instead of [] if an append action isn't used? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-01-09 16:50 +0100
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000

csiph-web