Permalink
Browse files

BF: itertools in Python 2.5 lacks .combinations

so we revert to simple cycling through permutations for older versions of Python
  • Loading branch information...
1 parent d32b5eb commit 8b10715888e3b9b61fced86ff7cee86943f73c0d @yarikoptic yarikoptic committed Mar 27, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 mvpa2/misc/support.py
View
@@ -13,7 +13,7 @@
import itertools
import math
import random
-import re, os
+import re, os, sys
# for SmartVersion
from distutils.version import Version
@@ -187,10 +187,12 @@ def xrandom_unique_combinations(L, n, k=None):
if k is None:
k = ncomb
- if ncomb < 1e6 or k > math.sqrt(ncomb):
+ if (ncomb < 1e6 or k > math.sqrt(ncomb)) \
+ and sys.version_info[:2] >= (2, 6):
# so there is no sense really to mess with controlling for
# non-repeats -- we can pre-generate all of them and just
# choose needed number of random samples
+ # Python2.5 doesn't have itertools.combinations
for s in random.sample(list(itertools.combinations(L, n)), k):
yield list(s)
else:

0 comments on commit 8b10715

Please sign in to comment.