Let's say I want to add a list of strings or just one to a DB:
names = ['Alice', 'Bob', 'Zoe']
and I want that add_to_db
will accept both cases
add_to_db(names)
add_to_db('John')
Is this the correct way to go:
def add_to_db(name_or_names):
if (...):
... # add a single name
else:
for name in name_or_names:
... # add a single name
commit_to_db()
What should I put in the first ...
, as condition to whether it's a list of strings or just a string (don't forget that string is also iterable)?