Here is what I work with ...
string1 = "Dog,cat,mouse,bird. Human."
def string_count(text):
text = re.split('\W+', text)
count = 0
for x in text:
count += 1
print count
print x
return text
print string_count(string1)
... and here is the conclusion ...
1
Dog
2
cat
3
mouse
4
bird
5
Human
6
['Dog', 'cat', 'mouse', 'bird', 'Human', '']
Why am I getting 6, although there are only 5 words? I can not get rid of ''(empty string)! It drives me crazy.
source
share