[Python-ideas] Vectorization [was Re: Add list.join() please]
David Mertz
mertz at gnosis.cx
Sat Feb 2 22:18:26 EST 2019
>
> I think it should follow the pre-existing behaviour of list, set, tuple,
> etc.
>
> >>> Vector("hello")
> <Vector of ['h', 'e', 'l', 'l', 'o']>
>
I try to keep the underlying datatype of the wrapped collection as much
as possible. Casting a string to a list changes that.
>>> Vector(d)
<Vector of ['Monday', 'Tuesday', 'Wednesday']>
>>> Vector(tuple(d))
<Vector of ('Monday', 'Tuesday', 'Wednesday')>
>>> Vector(set(d))
<Vector of {'Wednesday', 'Monday', 'Tuesday'}>
>>> from collections import deque
>>> Vector(deque(d))
<Vector of deque(['Monday', 'Tuesday', 'Wednesday'])>
Strings are already a Collection, there is not firm need cast them to a
list to live inside a Vector. I like the idea of maintaining the original
type if someone wants it back later (possibly after transformations of the
values).
Why is it pointless for a vector, but not for a list?
>
I guess it really isn't. I was thinking of just .upper() and .lower()
where upper/lower-casing each individual letter is the same as doing so to
the whole string. But for .replace() or .count() or .title() or
.swapcase() the meaning is very different if it is letter-at-a-time.
I guess a string gets unstringified pretty quickly no matter what though.
E.g. this seems like right behavior once we transform something:
>>> vstr = Vector('Monday')
>>> vstr
<Vector of 'Monday'>
>>> vstr.upper()
<Vector of "['M', 'O', 'N', 'D', 'A', 'Y']">
I dunno... I suppose I *could* do `self._it = "".join(self._it)` whenever I
do a transform on a string to keep the underlying iterable as a string.
But the point of a Vector really is sequences of strings not sequences of
characters.
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190202/5aad8233/attachment.html>
More information about the Python-ideas
mailing list