Rank items from sequence in colexicographical order.

    >>> [rank(i) for i in ('', 'a', 'b', 'ab', 'c')]
    [0, 1, 2, 3, 4]

    >>> rank('spam')
    299009

def rank(items, sequence=string.ascii_lowercase):
    """Rank items from sequence in colexicographical order.

    >>> [rank(i) for i in ('', 'a', 'b', 'ab', 'c')]
    [0, 1, 2, 3, 4]

    >>> rank('spam')
    299009
    """
    items = set(items)
    return sum(1 << i for i, s in enumerate(sequence) if s in items)