I have a utility method for printing lists of items, which also handles a few other things (like removing newline characters, etc.). I would like to expand my function so I can also pass it strings, and it will print the string the same way it would a list. Currently, it will iterate and print each line of the string separately. Here is an example:
#The function
def print_content(content):
#do some modification of the list
for i in content:
print(i)
#if I pass in a list, I will get output like:
>Item 1
>Item 2
>Item 3
#if I pass in a string, I will get output like:
>I
>t
>e
>m
>
>1
#But I would like it to read:
>Item 1
So my idea was to check if the variable was a string, and it it was, turn it into a list. However, if the variable is a list, leave it alone. How might I accomplish this or what other ways might I achieve this task?