Skip to content
Advertisement

How to skim itertools permutations?

Initial code:

JavaScript

Result:

JavaScript

Now I want to remove everything starting with “)” or “#”

and ends whit “(” or “#” and contenin “(“,”#”,”)”

JavaScript

With

JavaScript

Now the list is half in size “9k chart from 20k”.

ps: Now, how do i remove (‘A’, ‘B’, ‘C’, ‘(‘, ‘)’, ‘#’) this

I need to do this operations while the “iterator iterates” so I don’t have a big memory dump… The case with 12 numbers reach 300mb really quickly so I need to eliminate this combination from the pool of possible combinations.

To finally get:

JavaScript

Without any “(“,”#” and “#”,”)”.

How can I get this result efficiently?

Advertisement

Answer

I think is not necessary to build the first list (it will be oversized). You can produce filtered list in one step.

JavaScript

HIT

If you need to iterate over values, it can be done using another iterator in order to step over each record without allorate memory for all:

JavaScript
Advertisement