I\'m trying to create a function that receives a number as an argument and performs actions on that number to find out its closest powers of 2 that will then add up to that
The following binary solution combines @moose's use of enumerate()
with @gbriones.gdl's use of stride indexing and @gbriones.gdl's comment about one-lining it (actually, it was a comment about not one-lining it, but one-lining is fun).
def powers(n):
return [2**p for p,v in enumerate(bin(n)[:1:-1]) if int(v)]