Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43772
| Date | 2013-04-17 14:36 -0400 |
|---|---|
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: a couple of things I don't understand wrt lists |
| References | <mailman.668.1366126626.3114.python-list@python.org> <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> <mailman.718.1366191316.3114.python-list@python.org> <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.731.1366223819.3114.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a couple of things I don't understand wrt lists aaB <mecagonoisician@gmail.com> - 2013-04-16 17:37 +0200
Re: a couple of things I don't understand wrt lists John Gordon <gordon@panix.com> - 2013-04-16 16:43 +0000
Re: a couple of things I don't understand wrt lists Larry Hudson <orgnut@yahoo.com> - 2013-04-16 21:57 -0700
Re: a couple of things I don't understand wrt lists Serhiy Storchaka <storchaka@gmail.com> - 2013-04-17 12:35 +0300
Re: a couple of things I don't understand wrt lists 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-17 09:10 -0700
Re: a couple of things I don't understand wrt lists Ned Batchelder <ned@nedbatchelder.com> - 2013-04-17 14:36 -0400
Re: a couple of things I don't understand wrt lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-18 04:46 +1000
Re: a couple of things I don't understand wrt lists Chris Angelico <rosuav@gmail.com> - 2013-04-18 04:42 +1000
Re: a couple of things I don't understand wrt lists 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-17 09:10 -0700
csiph-web