What for -- for? (was A bug?)

Zachary Ware zachary.ware+pylist at gmail.com
Wed Oct 29 06:39:31 CET 2014


On Wed, Oct 29, 2014 at 12:15 AM, Rustom Mody <rustompmody at gmail.com> wrote:
> Maybe nicer to filter out the false's with a filter-false thus??
>
> def ff(d): return [n for n in d if d[n]]

Sure.  Or, combining things:

try:
    from collections import abc
except ImportError:
    import collections as abc
from abc import ABCMeta

abcs = [o for o in vars(abc).values() if isinstance(o, ABCMeta)]

def get_abcs(cls):
    return [abc for abc in abcs if issubclass(cls, abc)]

def get_abc_names(cls):
    return [abc.__name__ for abc in get_abcs(cls)]



Of course, that's 3 (progressively shorter) loops to get the names of
the ABCs of a class compared to 1 (fairly short in the first place)
loop for a map of relationships to all available ABCs, but optimizing
such a toy as this would just be an exercise in futility :)

-- 
Zach



More information about the Python-list mailing list