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.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to