[pyar] productos elementos de una lista
Daniel Moisset
dmoisset en machinalis.com
Jue Mayo 12 09:59:56 ART 2011
2011/5/12 p8queen <p8queen en gmail.com>
>
> me corrijo
> [y for x,y in zip(binNum,lista) if x=='1']
>
> >
> > python transforma a binario, pensalo.
Me gusta pensarlo como powereset, pero usando la receta de
http://docs.python.org/library/itertools.html
def product(t):
return reduce(operator.mul, t, 1)
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
l=[2,3,3]
print set(product(subset) for subset in powerset(l))
D.
More information about the pyar
mailing list