from container import Container


class Sack(Container):
    """
    A Sack with elements in no particular order.
    """

    def __init__(self):
        """
        Create a new, empty Sack self.

        @param Sack self: this Sack
        @rtype: None
        """
        # use a dictionary with string keys
        self._contents, self._key = {}, (1, 1)

    def add(self, obj):
        """
        Add object obj to random position of Sack self.

        @param Sack self: this Sack
        @param object obj: object to place on Sack
        @rtype: None
        """
        # increment key in a way that a dictionary stores
        # in no particular order...
        self._key = (self._key[0], self._key[1] + 1)
        self._contents[self._key] = obj

    def remove(self):
        """
        Remove and return some random element of Sack self.

        Assume Sack self is not empty.

        @param Sack self: this Sack
        @rtype: object

        >>> s = Sack()
        >>> s.add(7)
        >>> s.remove()
        7
        """
        return self._contents.popitem()[1]

    def is_empty(self):
        """
        Return whether Sack self is empty.

        @param Sack self: this Sack
        @rtype: bool
        """
        return len(self._contents) == 0


if __name__ == "__main__":
    import doctest
    doctest.testmod()
