[Python-ideas] [Python-Dev] hello, new dict addition for new eve ?
julien at tayon.net
Mon Jan 2 11:51:01 CET 2012
2011/12/31 Nathan Schneider <nathan at cmu.edu>:
> On Sat, Dec 31, 2011 at 4:55 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> On 12/31/2011 11:07 AM, julien tayon wrote:
>>> The question is a dict the same as a vector or as a set ?
>> A dict is a mapping, which is to say, a functional set of key,value pairs.
>> 'Functional' means that the keys are unique. This is a key property (pun
>> intended). A vector can be regarded as a functional set of count,value
>> pairs. Some languages use dicts for vectors. Even in Python, people use
>> dicts for sparse arrays of various dimensions, with unspecified pairs
>> assumed to have a 0 value.
Yes, a potentialy indefinite sparse value vector on a base at least
greater. For which the dimension is the path of keys to a value.
And I lamely admitted these were orthogonal in my mind to one another.
(therefore dicthing coupling problematics in the first time since I
will think of matrix later)
That is the reason, I intend to back down on any argumentation on
vectoriel meaning of dict without proper code to back up my claims :)
> It occurs to me that any argument for a vector interpretation of
> dicts, with element-wise operations, should apply equally well to
> lists and tuples, which are perhaps even more natural as
> representations for vectors. But of course, the + operator for
> sequences is interpreted as concatenation, not element-wise addition;
> it would be strange if the reverse were true for dicts.
I do admit I came to the fact you are right. And, I think that if two
keys were equals but not the value it should raise a collision
I could provide a consistent "set addition" for dict as an amend for
making so much noise :)
I would also provide sub.
I see a way to provide a dynamic dict to sets translator that would be
> The necessary resolution of key conflicts is what makes "+" feel less
> natural to me for dicts than it does for sequences, where the order of
> the operands is transparently reflected in the output. For dicts, in
> contrast, we are talking about a "lossy" union/combination where what
> is lost depends on the order of the operands—this is less transparent
> in the output. However it is spelled, though, I would be thrilled if
> such an operation were built in. :)
I can write my module for this. :) (I need to document myself on magic methods)
Well, if dict are vectors I must define :
- matrix (projection of vectors in an another base)
- distance (cosine similarity)
I will therefore be able to define the notion of proximity once done
that will tell if something is almost another thing
a word counter of a text should be close to the word counters of the
keyword it triggers.
PS I did not quite catch the functionnal thingy.
More information about the Python-ideas