I'm trying to work out a way to find out if a variable consists of one item or multiple items. I know that seems rather vague but hopefully the below will shed some light.
I've tried a few things, initially I thought the item looked like it was either a string or a list but using if isinstance(variable, basestring)
produces a True
on every value. I tried to check the length using len()
but of course as they are strings I always get a count of each character in the string. I also tried if isinstance(variable, list)
but of course this always had a False
.
I'm trying to print each item on its own, below is some sudo code and test data.
variable = ["[u'cheese']", "[u'grapes', u'oranges']", "[u'apple']"]
for item in variable:
if isinstance(item, list):
for i in item:
print i
else:
print item
Of course as mentioned this code does not work and I'm not sure how to tackle this. Any help would be appreciated.