Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion Python-Home-Challenges/Challenge_01.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Create a python progarm that do the following:
Create a python progarm that do the following:
1. Reads a text file
2. Returns the most recurring word in that file.

Expand Down
3 changes: 3 additions & 0 deletions Python-Home-Challenges/Creating_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd /home/$USER/
echo "please do not do what ever you want to do" > file.txt

22 changes: 22 additions & 0 deletions Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 keeping the recurring value from the file #
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.")
4 changes: 4 additions & 0 deletions Python-Home-Challenges/insructions_challenge#01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1. Open the "Creating_file.sh" file
2. execute the "Python-home-challenge#01-MaorWeiss.py" file

Have a nice day!