Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197085
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Lengthy numbers |
| Date | 2024-12-23 15:38 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <871pxy9di2.fsf@nightsong.com> (permalink) |
| References | <eXx9P.64901$o72.28550@fx01.ams4> <mailman.14.1734910364.2912.python-list@python.org> <extend-20241223090009@ram.dialup.fu-berlin.de> |
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].
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar
Lengthy numbers Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2024-12-21 11:49 +0000
Re: Lengthy numbers (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-12-21 21:03 +0000
Re: Lengthy numbers (Posting On Python-List Prohibited) Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2024-12-22 09:18 +0000
Re: Lengthy numbers (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-12-23 23:06 +0000
Re: Lengthy numbers Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2024-12-22 23:32 +0000
Re: Lengthy numbers Paul Rubin <no.email@nospam.invalid> - 2024-12-23 15:03 -0800
Re: Lengthy numbers Paul Rubin <no.email@nospam.invalid> - 2024-12-23 15:38 -0800
csiph-web