My own accounting python euler problem
Ozz
notvalid at wathever.com
Sun Nov 8 07:20:42 EST 2009
Oops,
> For listing all different subsets of a list (This is what I came up
> with. Can it be implemented shorter, btw?):
>
> def subsets(L):
> S = []
> if (len(L) == 1):
> return [L, []]
better to check for the empty set too, thus;
if (len(L) == 0):
return [[]]
The order of the sets looks better too;
>>> subset.subsets([1,2,3])
[[], [1], [2], [2, 1], [3], [3, 1], [3, 2], [3, 2, 1]]
cheers,
More information about the Python-list
mailing list