Re: Lengthy numbers

Liste des GroupesRevenir à cl python 
Sujet : Re: Lengthy numbers
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.python
Date : 24. Dec 2024, 00:38:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <871pxy9di2.fsf@nightsong.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
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].

Date Sujet#  Auteur
23 Dec 24 * Re: Lengthy numbers5Oscar Benjamin
23 Dec 24 +* Re: Lengthy numbers3Stefan Ram
24 Dec 24 i`* Re: Lengthy numbers2Paul Rubin
24 Dec 24 i `- Re: Lengthy numbers1Stefan Ram
24 Dec 24 `- Re: Lengthy numbers1Paul Rubin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal