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

MRAB python at mrabarnett.plus.com
Sat Feb 2 22:02:59 EST 2019


On 2019-02-03 02:03, David Mertz wrote:
> Slightly more on my initial behavior:
> 
>      >>> Vector({1:2,3:4})
>     TypeError: Ambiguity vectorizing a map, perhaps try it.keys(),
>     it.values(), or it.items()
> 
>      >>> Vector(37)
>     TypeError: Vector can only be initialized with an iterable
> 
>      >>> Vector("hello")
>     <Vector of 'hello'>
> 
> 
> I'm wondering if maybe making a vector out of a scalar should simply be 
> a length-one vector. What do you think?
> 
> Also, should a single string be treated like a vector of characters or 
> like a scalar? It feels kinda pointless to make a vector of characters 
> since I cannot think of anything it would do better than a plain string 
> already does (largely just the same thing slower).
> 
[snip]
I think it should follow the pre-existing behaviour of list, set, tuple, 
etc.

 >>> Vector("hello")
<Vector of ['h', 'e', 'l', 'l', 'o']>

Why is it pointless for a vector, but not for a list?


More information about the Python-ideas mailing list