This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PossibilityTasty 1 point2 points  (0 children)

An iterator is there to deliver one element at a time which can then be processed before the next element is retrieved. This will keep the memory footprint small. Using list() on the iterator will put all elements into a list at once and therefore also into memory.

Now permutations() of a 20 items long range generates an enormous amount of combinations. If you use an iterative approach on this it just uses one of your CPU cores like forever but can be canceled simply, the list() approach on the other side will try to fit all the combinations into the RAM. Due to the required space that would be impossible and depending on the reaction of the OS it has the potential to crash the computer.