On 2020-03-01 02:08, Christman, Roger Graydon wrote:
DL Neil asked:
How does one code a function/method signature so that
it will accept either a set of key-value pairs,
or the same data enclosed as a dict, as part of
a general-case and polymorphic solution?
Will this do for you?
def any_as
Emending my own note from moments ago:
def any_as_dict(*args, **kwargs):
if len(args) == 0:
my_dict = kwargs
elif type(args[0]) == type(dict()):
my_dict = args[0]
else:
my_dict = dict(args[0])
print(type(my_dict),my_dict)
>>> any_as_dict(a=1,b=2)
{'a': 1, 'b': 2}
>>> any_as_dict({'a':1, 'b':2}
DL Neil asked:
> How does one code a function/method signature so that
> it will accept either a set of key-value pairs,
> or the same data enclosed as a dict, as part of
> a general-case and polymorphic solution?
Will this do for you?
def any_as_dict(*args, **kwargs):
if len(args) == 0:
my_dic
How does one code a function/method signature so that it will accept
either a set of key-value pairs, or the same data enclosed as a dict, as
part of a general-case and polymorphic solution?
Wikipedia: polymorphism is the provision of a single interface to
entities of different types.
( https