def rle(iterable):
    """
    Run length encode a list.
    """
    iterable = iter(iterable)
    runlen = 1
    result = []
    try:
        previous = iterable.next()
    except __HOLE__:
        return []
    for element in iterable:
        if element == previous:
            runlen = runlen + 1
            continue
        else:
            if isinstance(previous, (types.ListType, types.TupleType)):
                previous = rle(previous)
            result.append([previous, runlen])
        previous = element
        runlen = 1
    if isinstance(previous, (types.ListType, types.TupleType)):
        previous = rle(previous)
    result.append([previous, runlen])
    return result
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/python/dxprofile.py/rle