This is very simple question

Fredrik Lundh fredrik at pythonware.com
Wed Apr 21 12:11:49 EDT 2004


but a lousy subject.

"Eric" <ekoome at yahoo.com> wrote;

> I would want to obtain a list of factors (multiples of 2) given a
> prime number in python.
>
> For example 13=[8,4,1], 5=[4,1], 7=[4,2,1], 15=[8,4,2,1]

>>> 8*4*1
32

> I would appreciate a fuction which would do this.

def func(x): return [2**i for i in range(3,0,-1) if x & 2**i]

</F>







More information about the Python-list mailing list