I was wondering what the most pythonic way would be to check if a function input is a string or a list. I want the user to be able to enter a list of strings or a string itself.
def example(input):
for string in input:
#Do something here.
print(string)
Obviously this will work in the input is a list of strings but not if the input is a single string. Would the best thing to do here is add type checking in the function itself?
def example(input):
if isinstance(input,list):
for string in input:
print(input)
#do something with strings
else:
print(input)
#do something with the single string
Thanks.