Ejemplo n.º 1
0
    __ge__ = __lt__

    def __hash__(self):
        """
        Hash based on value of elements.

        >>> m = pmap({pbag([1, 2]): "it's here!"})
        >>> m[pbag([2, 1])]
        "it's here!"
        >>> pbag([1, 1, 2]) in m
        False
        """
        return hash(self._counts)


Container.register(PBag)
Iterable.register(PBag)
Sized.register(PBag)
Hashable.register(PBag)


def b(*elements):
    """
    Construct a persistent bag.

    Takes an arbitrary number of arguments to insert into the new persistent
    bag.

    >>> b(1, 2, 3, 2)
    pbag([1, 2, 2, 3])
    """
Ejemplo n.º 2
0
        return PBag(result.persistent())

    def __hash__(self):
        """
        Hash based on value of elements.

        >>> m = pmap({pbag([1, 2]): "it's here!"})
        >>> m[pbag([2, 1])]
        "it's here!"
        >>> pbag([1, 1, 2]) in m
        False
        """
        return hash(self._counts)


Container.register(PBag)
Iterable.register(PBag)
Sized.register(PBag)
Hashable.register(PBag)


def b(*elements):
    """
    Construct a persistent bag.

    Takes an arbitrary number of arguments to insert into the new persistent
    bag.

    >>> b(1, 2, 3, 2)
    pbag([1, 2, 2, 3])
    """
__author__ = 'veradocs-web'

print "Container Abstract Base Class"
from collections import Container
print(Container.__subclasshook__(list))
print(Container.__subclasshook__(dict))
print(Container.__subclasshook__(set))
print(Container.__subclasshook__(tuple))
import string
print(Container.__subclasshook__(string))

class WorldContainer(Container):
    def __contains__(self, item):
        return False

print(Container.__subclasshook__(WorldContainer))
print(WorldContainer().__contains__(4))

print "Hashable Abstract Base Class"

from collections import Hashable
print(Hashable.__subclasshook__(string))

class WorldCHashable(Hashable):
    def __hash__(self, item):
        return id(item)

print(Hashable.__subclasshook__(WorldCHashable))
print(WorldCHashable().__hash__(4))