web.web.utils.Counter

Package web :: Package web :: Module utils :: Class Counter |
[hide private]
[frames] | no frames]

# Class Counter

source code

    object --+
             |
          dict --+
                 |
           Storage --+
                     |
                    Counter

Keeps count of how many times something is added.

    >>> c = counter()
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('y')
    >>> c
    <Counter {'y': 1, 'x': 5}>
    >>> c.most()
    ['x']

Instance Methods | [hide private]
add(self, n) | source code
most(self) Returns the keys with maximum count. | source code
least(self) Returns the keys with mininum count. | source code
percent(self, key) Returns what percentage a certain key is of all entries. | source code
sorted_keys(self) Returns keys sorted by value. | source code
sorted_values(self) Returns values sorted by value. | source code
sorted_items(self) Returns items sorted by value. | source code
__repr__(self) repr(x) | source code
Inherited from `Storage`: `__delattr__`, `__getattr__`, `__setattr__` Inherited from `dict`: `__cmp__`, `__contains__`, `__delitem__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__gt__`, `__init__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__setitem__`, `__sizeof__`, `clear`, `copy`, `fromkeys`, `get`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `pop`, `popitem`, `setdefault`, `update`, `values` Inherited from `object`: `__format__`, `__reduce__`, `__reduce_ex__`, `__str__`, `__subclasshook__`

Class Variables | [hide private]
Inherited from `dict`: `__hash__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### percent(self, key) | source code
Returns what percentage a certain key is of all entries.
    >>> c = counter()
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('y')
    >>> c.percent('x')
    0.75
    >>> c.percent('y')
    0.25

### sorted_keys(self) | source code
Returns keys sorted by value.
    >>> c = counter()
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('y')
    >>> c.sorted_keys()
    ['x', 'y']

### sorted_values(self) | source code
Returns values sorted by value.
    >>> c = counter()
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('y')
    >>> c.sorted_values()
    [2, 1]

### sorted_items(self) | source code
Returns items sorted by value.
    >>> c = counter()
    >>> c.add('x')
    >>> c.add('x')
    >>> c.add('y')
    >>> c.sorted_items()
    [('x', 2), ('y', 1)]

### __repr__(self) (Representation operator) | source code
repr(x) Overrides: object.__repr__ (inherited documentation)