Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.068 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.01; 'iterate': 0.09; 'cc:addr :python-list': 0.11; '(it': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mylist': 0.16; 'subject:Sort': 0.16; 'elements': 0.16; 'index': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'subject:) ': 0.29; 'message- id:@mail.gmail.com': 0.30; 'subject:time': 0.33; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:one': 0.36; 'list': 0.37; 'space': 0.40; 'read': 0.60; 'skip:n 10': 0.64; 'hey,': 0.75; 'more:': 0.84; 'oscar': 0.84; 'subject:space': 0.84; 'technically': 0.84; 'absolutely': 0.87; 'to:none': 0.92 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=6ue9cf9+FdJKiqa7hI6d1oX+pCk1xp1A9aef5MF7AlY=; b=ScsQBrkJu1Q5tpcBKPq782F9GiATOkwws/r3UfyGyBuI6BTehGiC19pYMqj8tzCA9q akt33vT7PYORGeHHXlIsWzeCO5aBjmfUw4Zk4tQMHmmA1nNcrlDFUPlxCZZs0GLHVz4v vIWDplpXav08KpBV3oCY/nm6FDEC+fCCLxcQth63jU8bq0GoJN1h+guVtlYlAG9Mah5G +xBWeUhpBv5MvitfcL2ikKqvQOalwbRRXpLh35dO2ZWGBenS7yw9jyrAIytc2SPRpoIp WJy12xhiOzx2AJ66XwuhvBDowIl3UPbFeKtPP6n8xrRUXnl3Nz1HkzOZk9UfAzA7Qj4v +h2g== MIME-Version: 1.0 X-Received: by 10.68.108.194 with SMTP id hm2mr38763692pbb.22.1392047528543; Mon, 10 Feb 2014 07:52:08 -0800 (PST) In-Reply-To: References: <52f80bca$0$29972$c3e8da3$5496439d@news.astraweb.com> <9671c418-cde8-4857-85ec-52380f8390eb@googlegroups.com> <433934582413720306.205290sturla.molden-gmail.com@news.gmane.org> <2079199387413737237.368296sturla.molden-gmail.com@news.gmane.org> Date: Tue, 11 Feb 2014 02:52:08 +1100 Subject: Re: Sort one sequence by O(n) in time and O(1) in space From: Chris Angelico Cc: Python List Content-Type: text/plain; charset=UTF-8 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392047537 news.xs4all.nl 2886 [2001:888:2000:d::a6]:37308 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65828 On Tue, Feb 11, 2014 at 2:45 AM, Oscar Benjamin wrote: > Something like > > mylist[:] = reorder_generator(mylist) > > won't work because the generator would need to access the data > non-sequentially (it would need to read elements after they were > overwritten). This would have O(1) space and O(n) time. It's absolutely perfect... except that you now don't technically have a list any more: mylist = reorder_generator(mylist) You can iterate over it, but can't index it. But hey, it complies with the space/time requirements! ChrisA