list - Limiting the number of combinations /permutations in python -
i going generate combination using itertools, when realized number of elements increase time taken increase exponentially. can limit or indicate maximum number of permutations produced itertools stop after limit reached.
what mean is:
currently have
#big_list list of lists permutation_list = list(itertools.product(*big_list))
currently permutation list has on 6 million permutations. pretty sure if add list, number hit billion mark.
what need significant amount of permutations (lets 5000). there way limit size of permutation_list produced?
you need use itertools.islice
, this
itertools.islice(itertools.product(*big_list), 5000)
it doesn't create entire list in memory, returns iterator consumes actual iterable lazily. can convert list this
list(itertools.islice(itertools.product(*big_list), 5000))
Comments
Post a Comment