-
Notifications
You must be signed in to change notification settings - Fork 11
Python-home-challenge#01-MaorWeiss #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
808a602
b879bfd
d5d833f
73dfa11
d069537
812b5c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
echo "Hi Hi Hello Hello Hi" > ~/PycharmProjects/file.txt | ||
echo "File created succesfully" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# HW03 - Open a text file and returns the most recurring word in that file. | ||
|
||
|
||
def read_file(): | ||
with open('../file.txt', 'r') as tmp_file: | ||
execute_file = tmp_file.readline() | ||
return execute_file | ||
|
||
|
||
def spilt_file(file): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 # | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: '{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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz add "if name" condition here |
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! |
There was a problem hiding this comment.
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