'''389. Find the Difference Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Input: s = "abcd" t = "abcde" Output: e ('e' is the letter that was added.) ''' deffindTheDifference(self, s, t): from collections import Counter s_counter = Counter(s) t_counter = Counter(t) returnlist(t_counter - s_counter)[0]
'''819. Most Common Word Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer is unique. Words in the list of banned words are given in lowercase, and free of punctuation. Words in the paragraph are not case sensitive. The answer is in lowercase. Example: Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit." banned = ["hit"] Output: "ball" ''' defmostCommonWord(self, paragraph, banned): import re from collections import Counter words = re.sub("[!|?|'|,|;|.]", '', paragraph).lower().split(' ') return (Counter(word for word in words if word notin banned).most_common(1)[0][0])