Here's what I'm working 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's the output…
1
Dog
2
cat
3
mouse
4
bird
5
Human
6
['Dog', 'cat', 'mouse', 'bird', 'Human', '']
Why am I getting a 6 even though there are only 5 words? I can't seem to get rid of the '' (empty string)! It's driving me insane.
{}button located above the text editor.