Use a boolean instead of hacky reference comparison in utils.iter.choice.

This commit is contained in:
Valentin Lorentz 2012-08-05 09:59:42 +02:00
parent 4ffaff0638
commit 393f78c573

View File

@ -98,13 +98,13 @@ def choice(iterable):
return random.choice(iterable) return random.choice(iterable)
else: else:
n = 1 n = 1
m = new.module('') # Guaranteed unique value. found = False
ret = m
for x in iterable: for x in iterable:
if random.random() < 1/n: if random.random() < 1/n:
ret = x ret = x
found = True
n += 1 n += 1
if ret is m: if not found:
raise IndexError raise IndexError
return ret return ret