List comprehensions in Python with mutable state between iterations

前端 未结 3 1376
情书的邮戳
情书的邮戳 2020-12-16 02:14

I have something which is an awful lot like a list comprehension in Python, except that it shares mutable state between iterations. Is there any way to do it with a list com

3条回答
  •  长情又很酷
    2020-12-16 02:47

    No. Deliberately no. Eventually they put in itertools.accumulate, which is the closest thing to an Officially Recommended way to implement recurrence relations in a functional manner, but it doesn't exist on 2.7. You could copy the "roughly equivalent to" Python implementation from the docs if you want.

提交回复
热议问题