鉴于多个列表:组合多个列表中的元素?
>>> foo = [hex, oct, abs, round, divmod, pow]
>>> bar = [format, ord, chr, ascii, bin]
and others
我与几个嵌套的条件
每个元素具有嵌套条件完成它1.retrieve可变从系统
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'bar', 'foo']
>>> [e for e in dir() if '__' not in e]
['bar', 'foo']
>>> mul_list = [e for e in dir() if '__' not in e]
>>> mul_list
['bar', 'foo']
2.obtain
>>> [ e.__name__ for single_list in mul_list for e in eval(single_list)]
['format', 'ord', 'chr', 'ascii', 'bin', 'hex', 'oct', 'abs', 'round', 'divmod', 'pow']
如何用简单的代码提取e legantly?
您是否尝试运行此代码,因为我在运行时遇到了错误 – Kallz
@Kallz如果'__'不在e]中,您需要在dir()中执行mul_list = [e for e]。 –
检查我的答案,给我错误 – Kallz