Is there a reason why recursive list comprehension is forbidden (or not recommended) in Python?

I believe list comprehension is one of Python's most useful features. I think it would be even more useful if Python allowed for recursion within a list comprehension, for something like generating Fibonacci numbers or primes. I know that Python had locals()['_[1]']to reference the list being created, but it was never recommended and was removed.

So, is there a reason Python developers don't want users to use recursion in list comprehension?

+4
source share
2 answers

, -, , . .

, . , (, ) , , , .

+3

, , , , , , , , , , .

.

, , . lambda, . - , .

+3

Source: https://habr.com/ru/post/1527960/


All Articles