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


Groups > comp.lang.python > #111544

Re: PEP Request: Advanced Data Structures

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: PEP Request: Advanced Data Structures
Date Sun, 17 Jul 2016 14:03:02 +1000
Lines 45
Message-ID <mailman.54.1468728185.2307.python-list@python.org> (permalink)
References <CAPTjJmrS84wQt-hKQyoOwZ18cKOQ84Ra5mGWNhwkaqO6OZ0EGA@mail.gmail.com> <20160717032709.GA61131@cskk.homeip.net> <CAPTjJmp2ofQ=1eo06g58L6Yx_fdSzWmy7ow7bWepP6wrQqeDyg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de W2Fr5bFj7p87zokZFQy62gip8bmqsBIR5WneVdf4pQ4A==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'attributes': 0.07; 'deny': 0.07; 'indices': 0.07; 'list?': 0.07; 'nicely': 0.07; 'subject:PEP': 0.07; 'invalidate': 0.09; 'item,': 0.09; 'pointers': 0.09; 'situation.': 0.09; 'python': 0.10; 'translate': 0.15; '"list': 0.16; '2016': 0.16; 'anyway).': 0.16; 'chasing': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'list)': 0.16; 'operation,': 0.16; 'pointers.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'slow,': 0.16; 'subject:Advanced': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'instance,': 0.18; 'refers': 0.18; 'language': 0.19; 'to:name :python-list@python.org': 0.20; 'assuming': 0.22; 'new,': 0.22; 'decide': 0.23; 'elements': 0.23; "python's": 0.23; 'header:In- Reply-To:1': 0.24; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'start,': 0.27; 'fine': 0.28; 'does,': 0.29; 'for,': 0.29; 'node': 0.29; 'sure,': 0.29; 'value)': 0.29; 'objects': 0.29; 'anywhere': 0.30; 'that.': 0.30; 'code': 0.30; 'possibly': 0.32; 'maybe': 0.33; 'useful': 0.33; 'doubt': 0.33; 'similar': 0.33; '(for': 0.34; 'structure': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'something': 0.35; 'item': 0.35; 'but': 0.36; 'too': 0.36; 'instead': 0.36; 'there': 0.36; 'structures': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'one,': 0.37; 'things': 0.38; 'doing': 0.38; 'no,': 0.38; 'stuff': 0.38; 'wrong': 0.38; 'someone': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'hang': 0.60; 'ever': 0.60; 'your': 0.60; "you'll": 0.61; 'skip:u 10': 0.61; 'design,': 0.61; 'here.': 0.62; 'linked': 0.63; 'relatively': 0.63; 'different': 0.63; 'benefit': 0.66; 'fundamental': 0.66; 'reverse': 0.66; 'subject:Data': 0.66; 'worth': 0.67; 'advantages': 0.72; 'jul': 0.72; 'overall': 0.72; 'chrisa': 0.84; 'costly': 0.84; 'damaged': 0.84; "else's": 0.84; 'afford': 0.91; 'improvement': 0.93
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; bh=2MPaOFbm4L9p5rp5TekYKj8/Rc/zsttKtpkAgAVAmEk=; b=mlpScdUhJAl3g9EfTo1V2v1Em7rVeUTGhjtEL1bjb11uzuWARFjnN6aAml0ayucUkU dAbQH558uLKfqtQyT/31O0jZwvMacuMWivjszpe0/KIw6cK81xMLuutKtILNpqaUzNX6 MWrq1IqFK49FuceOyDTVapcj5TDZ0XS0KMNuYtQMlkOGLYkccSumvqgZJKocwgTGYRh4 5CPYa3hvIz8QGRqU8RmcjHMHNLkspnc5QfaRDLt/+SxMVWwdGPMvbDdjOXSCH9nW7LI6 VJKC4YLEaFGhim2BrGa9tfd6trugkgUfR1KRXPIlLhZ5k8vrg5+DtrxJklw9FZ/8Dl3s Lczw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=2MPaOFbm4L9p5rp5TekYKj8/Rc/zsttKtpkAgAVAmEk=; b=NuOaSqc138Y+PLok7reMYbU+rhnyIM89X0wjquS4HRaB82Nzw4yri/EHrO5bve/nqR vvhyus7x9HAtWxogcFE7udm7hD6YNcly9I17ow3Rxh0tX9aR/ilQRmcnI/XPuevTDAeq JmDo196ndS78XyC30w7CyB2J8jbPfZX98zpOORny3BByEQEs+i2m374upUkheQdenHF/ NzZGdH6ix9a3FeQrFvn2u20Pudfm2CRp4oSeXHOunpVB8lbJAo8HPqmnj+d6BuCksTZj 4mD2dAndmUOcs7avzkAkA0FhRuCS0ZUsXxBaW9Cgr9+odkvltGgIJ/4z+CTaTAOvGbDN 8vJA==
X-Gm-Message-State ALyK8tK4Bn7BdcTcA+fJz8zLr+ynvGzBMCPiU1d6qPgkNyrNy0bu9ocE5ieOeWiM2HepDyjuBs8maLVIhjB3wQ==
X-Received by 10.194.169.98 with SMTP id ad2mr6489967wjc.117.1468728183095; Sat, 16 Jul 2016 21:03:03 -0700 (PDT)
In-Reply-To <20160717032709.GA61131@cskk.homeip.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <CAPTjJmp2ofQ=1eo06g58L6Yx_fdSzWmy7ow7bWepP6wrQqeDyg@mail.gmail.com>
X-Mailman-Original-References <CAPTjJmrS84wQt-hKQyoOwZ18cKOQ84Ra5mGWNhwkaqO6OZ0EGA@mail.gmail.com> <20160717032709.GA61131@cskk.homeip.net>
Xref csiph.com comp.lang.python:111544

Show key headers only | View raw


On Sun, Jul 17, 2016 at 1:27 PM,  <cs@zip.com.au> wrote:
>> Right, but how did you *get* that deep into the list? By following a
>> chain of pointers. That's a relatively costly operation, so the
>> benefit of not having to move all the following elements is damaged
>> some by the cost of chasing pointers to get there in the first place.
>
>
> No, you're assuming too much here. Consider:
>
>  LL = LinkedList()
>  item = LL.insert( (some, tuple, value) )
>  ... do lots of stuff with the list ...
>  ... now item refers to something that might be anywhere ...
>  item.add_after( (context, for, a, new, item, in , the, list) )
>  ...
>
> and any number of other scenarios of similar nature: note a node in the list
> and get to done things at or near that node at an arbirary other time.
>

Sure, that makes sense. The ability to hang onto a "list position" is
a useful one, I don't deny that. (Indices work if all you ever do is
append, but your add_after will invalidate any indices after that.) I
just very much doubt that the linked list will afford any overall
performance improvement over the standard CPython built-in list object
- and if it does, you're definitely in the realm of special-purpose
code for a specific situation. And there's nothing wrong with that.

Having not myself had a good early grounding in data structure design,
I think it's something worth teaching. And Python's fine at doing that
- the concepts of a linked list translate nicely into Python objects
and attributes - even though it'll never actually be something Python
needs. Once you've learned what the different fundamental structures
are, you'll have a better understanding of what's going on (for
instance, knowing the advantages and critical disadvantages of
hashtables like CPython's dict), and possibly know when to roll your
own instead of using someone else's (knowing that "lst.insert(0,
lst.pop(idx))" is slow, you might instead "lst.append(lst.pop(idx))"
and have your list in reverse order - a good start, but maybe you'd
decide to go linked-list anyway).

But for most jobs, just think in terms of abstract data structures,
and trust the language to do the details.

ChrisA

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


Thread

Re: PEP Request: Advanced Data Structures Chris Angelico <rosuav@gmail.com> - 2016-07-17 14:03 +1000

csiph-web