I wrote two example codes which share a same pattern.
As you can read below, I used if statement to not to pass keyword argument down to a sub function if the argument is None. I want to do it in a better way.
Please share your thoughts if you have an idea.
# example_1
def mysort(alist, key=None):
if key is None:
alist = sorted(alist)
else:
alist = sorted(alist, key=key)
return alist
# example_2
def create_index(index_name, mapping=None):
es = Elasticsearch()
if mapping in None:
response = es.indices.create(index=index_name)
else:
response = es.indices.create(index=index_name, body=mapping)
return respone