Path: csiph.com!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: 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; 'skip:[ 20': 0.04; 'argument': 0.05; 'correct.': 0.07; 'arguments': 0.09; 'arguments,': 0.09; 'python': 0.11; 'sections': 0.14; '"key"': 0.16; '[2,': 0.16; 'api,': 0.16; 'ascending': 0.16; 'declared': 0.16; 'descending': 0.16; 'determines': 0.16; 'dict': 0.16; 'handled.': 0.16; 'inheritance': 0.16; 'structs': 0.16; 'supplied': 0.16; 'tuple': 0.16; 'tuple,': 0.16; 'tuple.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'basically': 0.19; 'normally': 0.19; 'adds': 0.24; 'pointer': 0.24; 'header': 0.24; 'source': 0.25; 'order.': 0.26; 'references': 0.26; 'second': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'array': 0.29; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'int,': 0.31; 'object.': 0.31; 'struct': 0.31; 'class': 0.32; 'third': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'expected': 0.38; 'question,': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'fact': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'length': 0.61; 'first': 0.61; 'information': 0.63; 'more': 0.64; 'shares': 0.93; '2013': 0.98 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=qMNmTmT/nqhJzeYoj3xsHaotZJuMLR7Gn0ZBYbLVO7k=; b=C+F0zu6Nqhx/HDlvxGAtIm5E0WdhJLMFRHcTH5qY61PD1ohqIFrfGueccXyJgr+XYo rES1k8imeeHrz3WM556Jjebt3nDXK6KAy6T/A7QX66FP27hPt75mPNwzsMzj1DgUZOcZ +hu0je9h0KBEbuj7yCAfxmHm4jDUS5KnHdlC9C3LrqsmXh8ohSfRTkdKXQo/pPdI/pEE p09zj6Jclrsl99Nb2F1OoGUIwKA0G6GzUtpAwt/FvdvW/FHv+hJN917Mul81bxj29Cwn rPLsKnhQ0X8IL4xb5JiXF/S6pg64Hs+PLVI/iUoEWfqHiBlGbwOyu7oYoDS2BQp55+c8 eVLQ== X-Received: by 10.68.178.1 with SMTP id cu1mr3860855pbc.208.1371666090341; Wed, 19 Jun 2013 11:21:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87a79a3d-6f06-4aa3-a09f-48c695adeb4a@googlegroups.com> References: <9ca984d5-19d9-4e82-a305-2a2f5ee341fe@googlegroups.com> <87a79a3d-6f06-4aa3-a09f-48c695adeb4a@googlegroups.com> From: Ian Kelly Date: Wed, 19 Jun 2013 12:20:50 -0600 Subject: Re: Timsort in Cpython To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371666099 news.xs4all.nl 15932 [2001:888:2000:d::a6]:38503 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48739 On Wed, Jun 19, 2013 at 11:18 AM, wrote: > The second argument takes the tuple which determines which varialble(key) to use the comparator on. And the third determines whether to return the list in ascending or descending order. That's not exactly correct. The arguments are listed in that order, but in fact the arguments to list.sort are keyword-only and cannot be supplied positionally. So the "args" argument is expected to be an empty tuple, and the "kwds" argument is a dict that contains both the "key" and "reverse" arguments, if they were supplied. > But how do these PyObject* look in C? It's a pointer to a struct that contains information like the class and reference count of the object. > How does a PyListObject* look declared in CPython. That's a pointer to a larger struct that shares the same header as the PyObject* struct (which is basically how you do inheritance in C). It adds information like the length and capacity of the list, plus a pointer to an array of PyObject* that stores the contents of the list. > How would something like this list = [2, 1, 5, 6, 10] look in CPython. Or what about something more complicated -- mlist = [('A',1),('B',2),('C',3)]. To answer that question, you should really delve into the source and see what these structs actually look like. But the first is going to contain an array of five PyObject* values, each of which references an int, while the second is going to contain an array of three PyObject* values, each of which references a tuple. I also recommend that you read the sections of the Python docs that cover the C API, as those should help you understand how these structs are normally handled.