Some thougts on cartesian products
Christoph Zwerschke
cito at online.de
Sun Jan 22 14:07:34 EST 2006
Alex Martelli schrieb:
>> s = set(range(49)).powerset(6)
>> for x in range(10):
>> print s.pop()
>
> This is very systematic, not random;-). Still, using random.sample on s
> would indeed produce 12 random different tips!-)
Right, that would be systematic. What I wanted to write was:
s = set(range(49)).powerset(6)
for x in range(10):
c = choice(s)
print c
s.remove(c)
Of course you could also use random.sample again:
random.sample(set(range(49)).powerset(6), 10)
But this would be just as inefficient.
> tips = set()
> while len(tips) < 10:
> tip = frozenzet(random.sample(range(49), 6))
> tips.add(tip)
Yep, that's better. The amount of hand coding is even the same as above.
-- Christoph
More information about the Python-list
mailing list