Skip to content

Instantly share code, notes, and snippets.

@jkw552403
Created July 26, 2016 14:53
Show Gist options
  • Save jkw552403/793837d8f78e4e5d8ce88794dd47fe99 to your computer and use it in GitHub Desktop.
Save jkw552403/793837d8f78e4e5d8ce88794dd47fe99 to your computer and use it in GitHub Desktop.
import re
sent = 'a b c b c c A B C B C C'
match = re.search('\w+', sent)
while match:
word = match.group()
sent, count = re.subn(word, '', sent, flags=re.I)
match = re.search('\w+', sent)
print(word, count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment