Conversation
| print(x) | ||
| print("---------------") | ||
| words_in_text = dict() | ||
| my_file = open(where_file,"r") |
There was a problem hiding this comment.
you dont need to open file again, also, file must be closed after ward. best practice is to use "open...with" when working with files.
| print("Your file text is:") | ||
| for x in my_file: | ||
| print(x) | ||
| print("---------------") |
There was a problem hiding this comment.
that was just for my debugging, will be deleted.
| for key in list(words_in_text.keys()): | ||
| print(key, ":", words_in_text[key]) | ||
| print("---------------") | ||
| print (max(words_in_text.values())) |
There was a problem hiding this comment.
check you code again, output is wrong
There was a problem hiding this comment.
now its working with nice output
for highest in list(words_in_text.keys()): if max1 < words_in_text[highest]: max1 = words_in_text[highest] key1 = highest print ("The most recurring word is: ", key1," with ",max1, " times")
|
@AviadP |
| print(x) | ||
| print("---------------") | ||
| words_in_text = dict() | ||
| my_file = open(where_file,"r") |
There was a problem hiding this comment.
you dont need to open file again
There was a problem hiding this comment.
fix.
strange, i was sure that i removed it.
| if max1 < words_in_text[highest]: | ||
| max1 = words_in_text[highest] | ||
| key1 = highest | ||
| print ("The most recurring word is: ", key1," with ",max1, " times") |
There was a problem hiding this comment.
it is much better to use f' string. easier to read your code
| max1 = words_in_text[highest] | ||
| key1 = highest | ||
| print ("The most recurring word is: ", key1," with ",max1, " times") | ||
| my_file.close() No newline at end of file |
There was a problem hiding this comment.
you should close file as soon as you done with reading it, or better - use "with...open..."
|
@AviadP |
@AviadP