Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: Lengthy numbers Date: Mon, 23 Dec 2024 15:38:13 -0800 Organization: A noiseless patient Spider Lines: 16 Message-ID: <871pxy9di2.fsf@nightsong.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Tue, 24 Dec 2024 00:38:19 +0100 (CET) Injection-Info: dont-email.me; posting-host="0ec77f02b40872df5202021528adc871"; logging-data="1527689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/U6NkNhLK5pY12iw9v4n4s" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:ai7ePeHug8IL6mwyca7VcFgb/Ic= sha1:wUf/NMpJBjlSYOkk5Bodv+ZKxuE= Xref: csiph.com comp.lang.python:197085 ram@zedat.fu-berlin.de (Stefan Ram) writes: > So in theory, this would crank out an infinite list that looks like > [0, 0, 0, 0, ...]. In the real world, though, if you try to print or > use this list, your program will probably freeze up faster than the > 405 at rush hour. The freeze-up happens as soon as you create the list. Unfortunately iterators don't have anything like .extend so I don't see a way to create recursive ones like that, short of writing more verbose code using yield. In Haskell it is straightforward: fibonacci = 0 : 1 : zipWith (+) (tail fibonacci) main = print (take 10 fibonacci) should print [0,1,1,2,3,5,8,13,21,34].