a couple of things I don't understand wrt lists

Serhiy Storchaka storchaka at gmail.com
Wed Apr 17 11:35:07 CEST 2013


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)))





More information about the Python-list mailing list