Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
# HW03 - Open a text file and returns the most recurring word in that file.

with open(r'/home/$USER/', 'r') as fp:
f = fp.readline()
# Read file #
split_words_from_file = f.split()

# Creating variable for checking what is the recurring value #
biggest_counting = 0

for list_arg in split_words_from_file:
count = 0
for word in split_words_from_file:
if list_arg == word:
count += 1
if count > biggest_counting:
the_most_recurring_word = list_arg
biggest_counting = count


print(f"The most recurring word in the file is '{the_most_recurring_word}'")
print(f"which has appeared {biggest_counting} times.")

def read_file():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to get better use of your function, file name should be an argument

with open('/home/$USER/, 'r') as tmp_file:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test this code? i dont think it will work with this path

execute_file = tmp_file.readline()
return execute_file


def spilt_file(file):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var name file - you are not use file here, it is string, so var name might be misleading

split_words_from_file = file.split()
return split_words_from_file


def printing_the_recurring_word(split_words_from_file):
biggest_counting = 0
# Creating variable for keeping the recurring value from the file #
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz fix indetation

words = dict()
for list_arg in split_words_from_file:
if list_arg in words:
words[list_arg] = words[list_arg] + 1
else:
words[list_arg] = 1

for key in words:
if words[key] > biggest_counting:
biggest_counting = words[key]
the_most_recurring_word = key
print(f"The most recurring word in the file is '{the_most_recurring_word}'")
print(f"which has appeared {biggest_counting} times.")


def main():
my_file = read_file()
my_split_file = spilt_file(my_file)
printing_the_recurring_word(my_split_file)


main()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz add "if name" condition here