diff --git a/Home_Challenge1_Pyton.py b/Home_Challenge1_Pyton.py new file mode 100644 index 0000000..d2b0cdc --- /dev/null +++ b/Home_Challenge1_Pyton.py @@ -0,0 +1,28 @@ +file = open("C:/Users/tomer/PycharmProjects/HomeChallenge3/Readme.txt") +words = open("C:/Users/tomer/PycharmProjects/HomeChallenge3/Readme.txt").read().split() + +print(file.read()) +print(words) + + +def keywithmaxval(d): + """ a) create a list of the dict's keys and values; + b) return the key with the max value""" + v = list(d.values()) + k = list(d.keys()) + return k[v.index(max(v))] + + +def word_count(words): + counts = dict() + for word in words: + if word in counts: + counts[word] += 1 + else: + counts[word] = 1 + return keywithmaxval(counts), max(counts.values()) + + +print("max word is:", (word_count(words))) +print(file.read()) +file.close() diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 0000000..b5be70e --- /dev/null +++ b/Readme.txt @@ -0,0 +1 @@ +hello hello tomer hello tomer tomer maya maya hello eran tomer tomer roni roni roni roni roni roni \ No newline at end of file