Your problem is that in a
string
, spaces and characters count in the length.
So, the length of this variable, which is a string:
string = '123 abc'
is 7, because the space counts.
Now, to get the result you are looking for, you need to change the string to a list, which is a group of comma separated values. Note that we don't name our list 'list', because list()
is a function in python:
lst = ['2','5','11']
Now, when we check the length of our list:
>>> print len(lst)
3
And we get '3' as the result
To get your string to look like the list above:
>>> tl1 = "2, 5, 11"
>>> print tl1.split(',')
['2','5','11']
Then you could check the length using len()