diff --git a/firstCodeInPython.py b/firstCodeInPython.py new file mode 100644 index 0000000..2a9e30f --- /dev/null +++ b/firstCodeInPython.py @@ -0,0 +1,21 @@ +text = open('text.txt', 'r') +d = dict() +for line in text: + line = line.strip() + line = line.lower() + words = line.split(" ") + + for word in words: + if word in d: + d[word] = d[word] + 1 + else: + d[word] = 1 +for key in list(d.keys()): + print(key, ":", d[key]) + +mostapperdword=max(d,key=d.get) + +print (mostapperdword) +print(max(d.values())) + +print(f'The word that returns most times in the text file is: ' +mostapperdword+ ' and it returns ' ,max(d.values())) \ No newline at end of file diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..4c28ca6 --- /dev/null +++ b/text.txt @@ -0,0 +1,5 @@ +Mango banana apple pear +Banana grapes strawberry +Apple pear mango banana +Kiwi apple mango strawberry +mango \ No newline at end of file