'A dictionary of (feature, weight)-items of the features (terms, words) in a Document.
A vector can be used to compare the document to another document with a distance metric.
For example, vectors with 2 features (x, y) can be compared using 2D Euclidean distance.
Vectors that represent text documents can be compared using cosine similarity.'

def __init__(self, *args, **kwargs):

    s = kwargs.pop('sparse', True)
    f = ()
    w = None
    if (len(args) > 0):
        if isinstance(args[0], Vector):
            w = args[0].weight
        if isinstance(args[0], dict):
            f = args[0].items()
        elif hasattr(args[0], '__iter__'):
            f = iter(args[0])
    Vector.id += 1
    self.id = Vector.id
    self.weight = kwargs.pop('weight', w)
    self._norm = None
    f = chain(f, kwargs.items())
    f = ((k, v) for (k, v) in f if ((not s) or (v != 0)))
    readonlydict.__init__(self, f)
