Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: PEP Request: Advanced Data Structures Date: Sun, 17 Jul 2016 08:45:12 +1000 Lines: 45 Message-ID: References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de xzxtJPoIu8mXGi8XAWqyNAlS0g+kNuM8BBp6hgyZN41A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'cpython': 0.05; 'scaling': 0.07; 'subject:PEP': 0.07; 'cc:addr:python-list': 0.09; 'messing': 0.09; 'def': 0.13; '(but': 0.15; '2016': 0.16; 'chris,': 0.16; 'development:': 0.16; 'education:': 0.16; 'efficiency.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'item):': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'removal,': 0.16; 'subject:Advanced': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'basically': 0.18; 'instance,': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'code.': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'developing': 0.28; 'interface': 0.29; 'etc).': 0.29; "i'm": 0.30; 'code': 0.30; 'probably': 0.31; 'especially': 0.32; 'core': 0.32; 'skip:_ 10': 0.32; 'implement': 0.32; 'knows': 0.32; 'class': 0.33; 'doubt': 0.33; 'optimize': 0.33; 'structure': 0.34; 'add': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'item': 0.35; 'reply.': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'too': 0.36; 'instead': 0.36; '(and': 0.36; 'structures': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'thanks': 0.37; 'list.': 0.37; "won't": 0.38; 'anything': 0.38; 'why': 0.39; 'data': 0.39; 'sure': 0.39; 'where': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'provide': 0.61; 'linked': 0.63; 'more': 0.63; 'necessarily': 0.63; 'sample': 0.63; 'great': 0.63; 'subject:Data': 0.66; 'teach': 0.70; 'jul': 0.72; 'obvious': 0.76; 'vital': 0.76; 'chrisa': 0.84; 'simple:': 0.84; 'study,': 0.84; 'to:none': 0.91; 'shares': 0.93; 'education,': 0.96; 'hands': 0.96 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:cc :content-transfer-encoding; bh=3JPFvgXG8EKDnylv76Mc9gLNEQBaMh0XHa9LZKNqt3g=; b=0eWLR+RwD54pI/1gkbuTSPj2IaUFQ4HnR23UMeMBFl1RIlfw6Vogwl63T+MNUV60Lg oeRu2k6Wj01I/hfnsv+dyKftVmouFrHqf5XzOnvQmWreQKtUsb7UFr7xffnIT9evG3Tt P8vU73XFzmZS0h6tQGu8Y5PCmR+3Luuuoz47OHxgBy8PG/dOFEo9S/OW9M6QxWkp7WrG Ns9ekja+vrNPs5BHRSu/6tePQKnEVFQYF9h8Qz4RR7MLa5FkPT+VnPW+qVcUEVpVROLg aYoQhDkpCt/c9Z70xTRG+cs/bEoPg+GDhOGnzhG8q9Rdp7iDbPhR2xWciLo3WOS/Xmsb UTtQ== 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:cc:content-transfer-encoding; bh=3JPFvgXG8EKDnylv76Mc9gLNEQBaMh0XHa9LZKNqt3g=; b=aoOZa/69hQVI0aN6R7sHY180nXZJvsqv8lTdKPD7l+YLJH6kHlp+F1i/zCKHIxXyO+ iHKvrroB8GLq9FpSrbXA9+w4WTQP0dVER+u/yoe4Jp0076Q3lR6HUyjxsjx1nDiTwWUm 4d8kaZvS7QxXAa3TBTR28eJNzJMtIvZYCwyQKVKTnhYlxZChia9hjBAaflUKLyLXu6kY xxqEqr91aZuRPcfmEi47ON5ydOOYdjaYYd07WSAsyseUwq9N3QxoMjZ1U3uLGGz6SPSH 682FWviuEWhWWvJof82rtWh4lV4FcvsmCsr3G2lxxvnlruhrrF/ck2NppZR48QHrd/Kn 8veA== X-Gm-Message-State: ALyK8tJwK3CdEzw/CaNjjYCa62uM2/kMNzm9oLz8GTLK0WnD2lQwo9qrar01TOFiUtj9cs01MxSfmcg5ggZ5GQ== X-Received: by 10.194.169.98 with SMTP id ad2mr5885746wjc.117.1468709113617; Sat, 16 Jul 2016 15:45:13 -0700 (PDT) In-Reply-To: <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> Xref: csiph.com comp.lang.python:111528 On Sun, Jul 17, 2016 at 8:33 AM, Shrey Desai wrote: > Hi Chris, thanks for the reply. There's a couple of reasons why I would n= eed a Linked List (and other data structures): > - Education: the Linked List is a core data structure that CS undergradua= tes (among others) use and study, so it is vital that they have hands on ac= cess to them. A list is basically a dynamic array; the only property it sha= res with a Linked List is that it's dynamic. > - Development: the use of correct data structures is important when devel= oping applications, especially for issues like scaling and efficiency. For = instance, when working with polynomials, Linked Lists provide a great inter= face to access and edit them. > For education, I wouldn't worry too much about performance or edge cases, and just use something really simple: class LinkedList: def __init__(self): self.head =3D self.tail =3D None def append(self, item): if self.tail: self.tail =3D self.tail.append(item) self.head =3D self.tail =3D _listitem(item) class _listitem: def __init__(self, item): self.item =3D item self.next =3D None def append(self, item): self.next =3D type(self)(item) return self.next Then add other methods as you teach them (iteration, item removal, etc). Performance is probably terrible, but who cares? You won't notice it in sample code. For development, I'm pretty sure the native CPython list type is going to out-perform anything you could implement as a linked list. Even more so if you're using PyPy, where it knows how to optimize the list (but won't necessarily be able to optimize your type). Instead of messing around with data types, just implement your code using the most simple and obvious style, and worry about performance/scaling/efficiency only if and when you find out that that's a bottleneck. I very much doubt that it will be. ChrisA