Created
August 13, 2020 04:22
-
-
Save avwave/d07d4471c98068cedbb9abea76b6364d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def wordWoodyTinny(word): | |
c = ["W" if letter.upper() in "WODML" else "T" if letter.upper() in "TINEC" else "C" for letter in word] | |
return "Tinny" if "T" in c else "Woody" if "W" in c else "Middle Class" | |
def woodyTinny(sentence): | |
wordlist = re.split('\W', sentence) | |
mapping = [wordWoodyTinny(word) for word in wordlist] | |
freq = {} | |
for item in mapping: | |
if (item in freq): | |
freq[item] += 1 | |
else: | |
freq[item] = 1 | |
print(freq) | |
woodyTinny("Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment