Last active
October 28, 2018 14:24
-
-
Save AhmedMourad0/2424fed2a5d1ed2233777f72357ab922 to your computer and use it in GitHub Desktop.
A college thing.
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
def bubble_sort(tuples): | |
for iteration in range(len(tuples) - 1, 0, -1): | |
for i in range(iteration): | |
if tuples[i][1] > tuples[i + 1][1]: | |
temp = tuples[i] | |
tuples[i] = tuples[i + 1] | |
tuples[i + 1] = temp | |
return tuples | |
def lower(iterable): | |
for i in range(len(iterable)): | |
iterable[i] = iterable[i].lower() | |
return iterable | |
commonWords = lower(["is", "the", "am"]) | |
commonWords.append(".") | |
allWords = lower(["football", "is", "sport", "is", "game", "the", "sport", "football", "am", "sport"]) | |
words = {} | |
for word in allWords: | |
if word not in commonWords: | |
if word in words: | |
words[word] += 1 | |
else: | |
words[word] = 1 | |
print(words) | |
orderedWords = bubble_sort(list(words.items())) | |
print(orderedWords) | |
for i in range(len(orderedWords)): | |
orderedWords[i] = orderedWords[i][0] | |
print(orderedWords) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment