Python is faster than C

Carl Banks imbosol at aerojockey.invalid
Sun Apr 4 20:14:58 EDT 2004


Raymond Hettinger wrote:
> 
> 
> [Armin Rigo] 
>> >>> enumerate([6,7,8,9])         # uh ?
>> <enumerate object at 0x401a102c>
> 
> This got me thinking about how much I would like to see the contents
> of an iterator at the interactive prompt.
> 
> I wonder if the read-eval-print loop could be trained to make a better
> display:
> 
> # rough pseudo-code sketch
> while 1:
>    command = raw_input()
>    result = eval(command)
>    if result is None:
>        continue
>    if is_iterator(result):
>        result, copy = itertools.tee(result)
>        print "<%s object at 0x%8x:" % 
>                (type(result).__name__, id(result)),
>        for elem in itertools.islice(copy, 3):
>            print repr(elem), 
>        else:
>            print '...',
>        print '>'
>    else:
>        print repr(result)
>    _ = result
> 
> 
> # intended result
>>>> enumerate('abcdefgh')
> <enumerate object at 0x401a102c:  (0, 'a') (1, 'b') (2, 'c') ...>
>>>> list(_)
> [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g'),
> (7, 'h'), (8, 'i'), (9, 'j'), (10, 'k'), (11, 'l'), (12, 'm'), (13,
> 'n')]


I thought this myself, but what if the iterator is computationally
intensive?


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list