Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'referring': 0.07; '[0]': 0.09; 'lines:': 0.09; 'python:': 0.09; 'used.': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'cleaned': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'returned': 0.30; 'larry': 0.31; 'object.': 0.31; 'subject:lists': 0.35; 'there': 0.35; 'object,': 0.36; 'two': 0.37; 'list': 0.37; '8bit%:86': 0.38; 'pm,': 0.38; 'new': 0.61; 'line!': 0.84 Date: Wed, 17 Apr 2013 14:36:34 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: 88888 Dihedral Subject: Re: a couple of things I don't understand wrt lists References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> In-Reply-To: <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: python-list@python.org 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366223819 news.xs4all.nl 2172 [2001:888:2000:d::a6]:60302 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43772 On 4/17/2013 12:10 PM, 88888 Dihedral wrote: > Serhiy Storchaka於 2013年4月17日星期三UTC+8下午5時35分07秒寫道: >> 17.04.13 07:57, Larry Hudson написав(ла): >> >>> So using a list comprehension you can do it in two lines: >>> def get_rule(num): >>> bs = bin(num)[2:] >>> return [0] * (8 - len(bs)) + [int(i) for i in bs] >> >> >> You can do it in one line! >> >> >> >> def get_rule(num): >> >> return list(map(int, '{:08b}'.format(num))) > Well, a new object is returned and can be used. > Then who is going to clean up the object when required? This is a key thing to understand about Python: memory is managed automatically, no one has to clean up the object. Once there are no names referring to the object, it will be cleaned up automatically. --Ned.