top | item 38035524 (no title) daureg | 2 years ago doesn't it use a lot of memory since we're only interested in the last value? discuss order hn newest FreakLegion|2 years ago You can do the same thing with a generator. x = 0 deque((x := x + 1 for _ in range(10)), maxlen=0) print(x) >> 10 Using deque to consume generators is an old trick documented in the itertools recipes: https://docs.python.org/3/library/itertools.html#itertools-r...
FreakLegion|2 years ago You can do the same thing with a generator. x = 0 deque((x := x + 1 for _ in range(10)), maxlen=0) print(x) >> 10 Using deque to consume generators is an old trick documented in the itertools recipes: https://docs.python.org/3/library/itertools.html#itertools-r...
FreakLegion|2 years ago