Skip to content

Commit 36b705f

Browse files
committed
Add error checking
1 parent 7ded35d commit 36b705f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Doc/library/random.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ or the :pypi:`more-itertools` project:
665665
def random_derangement(iterable):
666666
"Choose a permutation where no element is in its original position."
667667
seq = tuple(iterable)
668+
if len(seq) < 2:
669+
raise ValueError('derangments require at least two values')
668670
while True:
669671
perm = random_permutation(seq)
670672
if all(p != q for p, q in zip(seq, perm)):

0 commit comments

Comments
 (0)