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


Groups > comp.lang.python > #48739

Re: Timsort in Cpython

References <9ca984d5-19d9-4e82-a305-2a2f5ee341fe@googlegroups.com> <b3df2c76-b191-4cbb-9859-874b534a17e5@googlegroups.com> <mailman.3459.1371415158.3114.python-list@python.org> <87a79a3d-6f06-4aa3-a09f-48c695adeb4a@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2013-06-19 12:20 -0600
Subject Re: Timsort in Cpython
Newsgroups comp.lang.python
Message-ID <mailman.3594.1371666099.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jun 19, 2013 at 11:18 AM,  <sean.westfall@gmail.com> 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.

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


Thread

Timsort in Cpython alphonse23@gmail.com - 2013-06-15 12:44 -0700
  Re: Timsort in Cpython Zachary Ware <zachary.ware+pylist@gmail.com> - 2013-06-15 14:55 -0500
  Re: Timsort in Cpython Robert Kern <robert.kern@gmail.com> - 2013-06-15 21:00 +0100
  Re: Timsort in Cpython alphonse23@gmail.com - 2013-06-15 13:21 -0700
    Re: Timsort in Cpython Robert Kern <robert.kern@gmail.com> - 2013-06-15 21:55 +0100
      Re: Timsort in Cpython alphonse23@gmail.com - 2013-06-15 14:43 -0700
    Re: Timsort in Cpython Terry Reedy <tjreedy@udel.edu> - 2013-06-15 22:56 -0400
  Re: Timsort in Cpython alphonse23@gmail.com - 2013-06-15 21:05 -0700
    Re: Timsort in Cpython mm0fmf <none@mailinator.com> - 2013-06-16 14:08 +0100
      Re: Timsort in Cpython alphonse23@gmail.com - 2013-06-16 09:15 -0700
        Re: Timsort in Cpython Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-16 16:16 -0400
          Re: Timsort in Cpython sean.westfall@gmail.com - 2013-06-19 10:10 -0700
    Re: Timsort in Cpython Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-16 14:33 -0600
      Re: Timsort in Cpython sean.westfall@gmail.com - 2013-06-19 10:18 -0700
        Re: Timsort in Cpython Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-19 12:20 -0600

csiph-web