Can someone suggest a Python implementation of the Haskell span
function?
span :: (a -> Bool) -> [a] -> ([a],[a])
span p [] = ([],[])
span p (x:xs) = if p x then (x:ys,zs)
else ([],x:xs)
where (ys,zs) = span p xs
I'd like it to be lazy in each argument individually, so a list of two generators. I'd prefer if it were implemented recursively, to get a sense of Python definitions where you recurse on the tail of the list. Perhaps with yield from
, if appropriate.