Proposed new syntax

Steve D'Aprano steve+python at pearwood.info
Tue Aug 15 07:32:51 EDT 2017


On Tue, 15 Aug 2017 01:26 pm, Paul Rubin wrote:

> Steve D'Aprano <steve+python at pearwood.info> writes:
[...]
>> In Haskell, you cannot get the last N elements of a list without
>> allocating memory for the previous ones.
> 
>     lastn n xxs@(x:xs)
>       | length (take n xs) == n-1 = xxs
>       | otherwise = lastn n xs
> 
>     main = print . lastn 5 $ [1..10000000]
> 
>     *Main> main
>     [9999996,9999997,9999998,9999999,10000000]
> 
> works for me. 

Right. Did you read the Stackoverflow page I linked to? They all pretty much say
the same thing, although most of the given solutions use `drop`. Sorry if my
wording was unclear.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list