Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'elements.': 0.05; 'apis': 0.07; 'friday,': 0.07; 'pretend': 0.07; '[1,': 0.09; 'accepts': 0.09; "ain't": 0.09; 'array.': 0.09; 'immutable': 0.09; 'objects.': 0.09; 'spelled': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'size,': 0.13; 'languages,': 0.15; '3],': 0.16; 'apis.': 0.16; 'count.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'immutable,': 0.16; 'list"': 0.16; 'objects;': 0.16; 'opendir': 0.16; 'sorts': 0.16; 'url:gnu': 0.16; 'wrote:': 0.16; 'element': 0.18; 'pointer': 0.18; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'pass': 0.22; '2015': 0.23; 'references': 0.23; 'header:In-Reply-To:1': 0.24; 'data,': 0.27; 'entries': 0.27; 'message-id:@mail.gmail.com': 0.28; 'arrays': 0.29; 'url:software': 0.29; 'array': 0.29; 'sense': 0.29; 'there.': 0.30; 'certainly': 0.31; 'fri,': 0.31; 'programmers': 0.31; 'point': 0.33; 'common': 0.33; "d'aprano": 0.33; 'lets': 0.33; 'null': 0.33; 'shorter': 0.33; 'steven': 0.33; 'subject:?': 0.34; 'received:google.com': 0.34; 'lists': 0.34; 'gives': 0.35; 'next': 0.35; 'identified': 0.35; 'lists.': 0.35; 'something': 0.35; 'really': 0.35; 'list': 0.35; "isn't": 0.35; 'but': 0.36; 'url:org': 0.36; '(and': 0.36; 'subject:: ': 0.37; 'say': 0.38; 'pm,': 0.39; 'things': 0.39; 'your': 0.60; 'more': 0.62; 'linked': 0.63; 'dont': 0.64; 'talking': 0.67; 'saw': 0.76; 'chrisa': 0.84; 'stashed': 0.84; 'utc+5:30,': 0.84; 'valid,': 0.84; 'to:none': 0.90 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=o6n58Psre3bNmx/1CLYWzEIGVQAUcjDqyBvDx7fd6aE=; b=ThHFwLOCV7lH62mF2izP8R3soRst3kAZvO2R3EUEK0lzIidez210YtTczoPeSNKM59 5DYuPwqgkq+n8dQuqIOhYShZG+ABJ5gxgn3Cp2/qE2N6t1LmP2nsDHiRUyu/02tps4Q5 gPRkYYb6nb3pplFWgRz7ygD2Uv3AhaTJBY0ZxE6zUeFdrGjrT24gqNfpfEt2e627iwjn E+z9MeZKS5sW3doXp7plZjL0Giqy8vt8+I0WExtr0M0srP1OJWAeNWL8AKjBoEuq0FCO zFOcrwyIKy3tyIEP0bRrozLethitkm9GWc10EpiJn0uuECuK8JAtdHYjIohI++bpucXl w0Eg== MIME-Version: 1.0 X-Received: by 10.42.154.65 with SMTP id p1mr12697737icw.26.1433541562775; Fri, 05 Jun 2015 14:59:22 -0700 (PDT) In-Reply-To: <33a2f501-5587-4fd9-91fa-7094d4f6c512@googlegroups.com> References: <3bbe49da-e989-4a8c-a8a9-75d3a786f508@googlegroups.com> <557056f9$0$13009$c3e8da3$5496439d@news.astraweb.com> <5570ce43$0$12991$c3e8da3$5496439d@news.astraweb.com> <55710b69$0$12980$c3e8da3$5496439d@news.astraweb.com> <6c78b294-efd6-4096-a572-1841aa71a5eb@googlegroups.com> <557182af$0$13014$c3e8da3$5496439d@news.astraweb.com> <33a2f501-5587-4fd9-91fa-7094d4f6c512@googlegroups.com> Date: Sat, 6 Jun 2015 07:59:22 +1000 Subject: Re: Can Python function return multiple data? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433541572 news.xs4all.nl 2932 [2001:888:2000:d::a6]:44876 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92163 On Fri, Jun 5, 2015 at 11:29 PM, Rustom Mody wrote: > On Friday, June 5, 2015 at 4:36:35 PM UTC+5:30, Steven D'Aprano wrote: >> On Fri, 5 Jun 2015 01:16 pm, Rustom Mody wrote: >> > The abstract platonic immutable list is non-existent in python >> >> Just pretend that "immutable list" is spelled "tuple". > > Ok lets say I make no fuss about the need to 'pretend'. > > And I try... > >>>> a=[1,2,3] >>>> b=(a,a) >>>> a > [1, 2, 3] >>>> b > ([1, 2, 3], [1, 2, 3]) >>>> a.append(4) >>>> b > ([1, 2, 3, 4], [1, 2, 3, 4]) Congrats! You just proved that an object can itself be immutable, but can contain references to mutables. Ain't that awesome? Did you have a point? > It was an analogy. > C programmers use lists all right all the time. > However until they see something like python, they dont know that they never > REALLY saw lists. ie lists in python are more first-class than C. If you're talking about the things C programmers use all the time, they're not linked lists, they're arrays - identified by base pointer and element count. Linked lists are common in LISPy languages, but not all that common in C, nor C-derived APIs. Most APIs designed for C usage are either array-based or generator-based. http://www.gnu.org/software/libc/manual/html_node/Scanning-Directory-Content.html Array-based: scandir accepts a pointer-to-pointer, which it populates with a pointer to freshly-allocated data, and it returns the number of entries stashed there. http://www.gnu.org/software/libc/manual/html_node/Opening-a-Directory.html http://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html Generator-based: opendir returns a generator, readdir gives the next result or NULL http://www.gnu.org/software/libc/manual/html_node/Array-Sort-Function.html Array-based: pass it a base pointer and a count (and an object size, since it's completely generic), and it sorts the elements. Your point is still broadly valid, though; these arrays are not first-class objects. They do have their own little quirks; so long as the original array isn't deallocated, you can efficiently work with views by simply using a base pointer inside the original array and a length that's shorter than the whole array. Very convenient if you need it, but most certainly not first-class lists, and can cause problems if you're not careful. Python lists truly are first-class objects; "more first-class than C" in the sense that 1 is more true than 0. ChrisA