I've already looked at this and this and this, but I'm still confused and unsure where/how to use generators/yield
and splat/*
.
Use case: Sanitize inputs before further manipulating them.
def sanitize_inputs(*args):
for arg in args:
if arg == '':
yield None
else:
yield arg
"{}|{}".format(sanitize_inputs('abc',''))
Ideally, sanitize_inputs
should return an expanded list so the string substitution will work.