0

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.

Peter
  • 1,065
  • 14
  • 29

1 Answers1

0

Well... after this was siting in draft state, figured it out, thanks to this

In: "{}|{}".format(*sanitize_inputs('abc',''))
Out: 'abc|None'
Peter
  • 1,065
  • 14
  • 29