[Python-ideas] Vectorization [was Re: Add list.join() please]

David Mertz mertz at gnosis.cx
Sat Feb 2 18:43:51 EST 2019


On Sat, Feb 2, 2019, 6:23 PM Christopher Barker

> a_list_of_strings.strip().lower().title()
>
> is a lot nicer than:
>
> [s.title() for s in (s.lower() for s in [s.strip(s) for s in
> a_list_of_strings])]
>
> or
>
> list(map(str.title, (map(str.lower, (map(str.strip, a_list_of_strings))))
> # untested
>

I'm warming up some. But is this imagined as vectors of strings, or as
generically homogeneous objects? And what is homogeneity exactly in the
face of duck typing?

Absent the vector wrapping, I think I might write this for your example:

map(lambda s: s..strip().lower().title(), a_list_of_strings)

That's slightly longer, but just by the length of the word lambda.

One could write a wrapper to vectorize pretty easily. So maybe:

Vector(a_list_of_strings).strip().lower().title()

This would just pass along the methods to the individual items, and
wouldn't need to think about typing per se. Maybe other objects happen to
have those three methods, so are string-like in a duck way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190202/e250aefa/attachment.html>


More information about the Python-ideas mailing list