11
votes
Extract unique email addresses from a text file
Explicit contract
Returning an empty list to indicate "file not found" is probably the only big sin here. Now your function returns the same empty list in both of the following cases:
File ...
10
votes
Extract unique email addresses from a text file
High level advice: the RFCs have many subtle details — prefer to rely on a well tested library that understands the spec before you roll your own.
design of Public API
...
7
votes
Iterative Deepening A* implementation of 15 Puzzle solver in Python
Bug
get_valid_ordered_moves returns invalid moves. You can't check row overflow by modified index alone, so your check will allow move from cell number 7 (...
7
votes
6
votes
Extract unique email addresses from a text file
Documentation
The PEP 8 style guide recommends
adding docstrings for functions. For example:
...
5
votes
Extract unique email addresses from a text file
One thing that always annoys me about sites collecting email addresses.
user@EXAMPLE.COM are the same ...
4
votes
Extract unique email addresses from a text file
We have seen several answers about how to improve your python, and why using a regex to detect a mail address is a bad idea, but there's one more thing I want to point out:
Reading a complete file in ...
3
votes
Functions to check if object matches type and reverse a string
Let's first look at the is_type function. This is about handling types, and indicative that one should be careful in separating
something being of a type – ...
2
votes
Kaggle Notebook for Identifying House Plants
module docstring
First, in any language, avoid repeated "----" or "===="
ASCII art in comments.
Prefer to use whatever tools the language
offers in order to better organize your ...
2
votes
Value at Risk forecast generator
Comments
Remove commented-out code to reduce clutter:
# Print other information (optional)
# print(daily_return.shape, len(weights))
# print(daily_return.columns)
...
2
votes
Accepted
Kaggle Notebook for Identifying House Plants
Overview
The code layout and organization is good, the function docstrings are helpful
and you used meaningful names for functions and variables.
Comments
It is good that you added comments at the top ...
2
votes
Iterative Deepening A* implementation of 15 Puzzle solver in Python
Here are some minor style suggestions not covered in the previous answer.
Simpler
The print_board inner for loop is slightly ...
2
votes
Combination of three vocabulary sets
Your set of loops and conditionals to build result can be built more declaratively using a list comprehension.
...
2
votes
Accepted
Splitting input text into fixed-size overlapping word chunks
Your tests are pretty good, and helped me during refactoring. I think they all make sense save the empty case: in my refactor an empty string generates no chunks rather than one empty chunk.
I can't ...
1
vote
the 10001st prime number
While a sieve is a good way to calculate primes, if you need to find some arbitrary Nth prime, your memory requirements may become onerous. This can be improved by implementing a segmented sieve, ...
1
vote
Accepted
Flask App for Weather Prediction Using Machine Learning
Comments
It is great that you incorporated advice from previous reviews. However,
there is no need to permanently add comments to the code which merely
state that you did so. For example, comments ...
1
vote
Accepted
Predictive Maintenance ML Project in Jupyter Notebook
Documentation
The PEP 8 style guide recommends
adding a docstring at the top of the code to summarize its purpose.
You could convert the header comments to a docstring:
...
1
vote
Accepted
ML Project: Predictive Maintenance in Jupyter Notebook
Simpler
You can simplify the logic of if/else statements like this:
if not numeric_df_for_corr.empty:
else:
by removing the <...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
python × 15566python-3.x × 5186
performance × 2365
beginner × 2002
python-2.x × 1231
algorithm × 1205
programming-challenge × 1038
numpy × 752
object-oriented × 725
pandas × 597
game × 538
strings × 489
web-scraping × 430
time-limit-exceeded × 395
tkinter × 352
parsing × 322
django × 306
csv × 304
hash-map × 295
random × 252
recursion × 245
pygame × 244
file-system × 237
regex × 235
reinventing-the-wheel × 225