Ich versuche builtins durch ihre Typen durch die folgenden Schritte, um sieabrufen ‚builtins‘ jeweils durch ihre Typen
Zuerst Rufen Sie alle Typen in builtins
mit ‚Set‘
total_builtins = dir(__builtins__)
total_types = {type(eval(i)) for i in total_builtins}
In [95]: total_types
Out[95]:
{NoneType,
NotImplementedType,
_sitebuiltins._Helper,
_sitebuiltins._Printer,
bool,
builtin_function_or_method,
ellipsis,
function,
method,
str,
type}
#Subtract type of 'type'
total_types = total_types.pop()
In [120]: len(total_types)
Out[120]: 10
Zweite Gruppe abzurufen unter Verwendung von dict,
In [117]: {mytype:[i for i in total_bins if isinstance(eval(i), mytype)]
for mytype in total_types}
Out[117]:
{NoneType: ['None', '__loader__', '__package__', '__spec__'],
NotImplementedType: ['NotImplemented'],
_sitebuiltins._Helper: ['help'],
_sitebuiltins._Printer: ['copyright', 'credits', 'license'],
bool: ['False', 'True', '__IPYTHON__', '__debug__'],
builtin_function_or_method: ['__build_class__',
'__import__',
....],
ellipsis: ['Ellipsis'],
function: ['display'],
method: ['get_ipython'],
str: ['__doc__', '__name__']}
was das gewünschte Ergebnis produziert, aber ein bisschen zu viel für die Aufgabe aussieht (vor allem die mehrere verschachtelte Verständnis).
Wie löst man ein solches Problem auf intelligente Weise?