def flatten(l):
    for el in l:
        if isinstance(el, collections.Iterable) and not isinstance(el,
            str):
            for sub in flatten(el):
                yield sub
Длина 2d-списка в питоне