13
votes
Accepted
10
votes
News API in Python
Naming
NewsConcerning is styled in the way PEP 8 would tell us to style a class name. As function it should be in snake case: ...
5
votes
News API in Python
single responsibility
The SRP
says that a function should do one thing well.
The expression that replaces "concerning" and other stop words
should be in a helper function.
For one thing, ...
5
votes
News API in Python
String Replacements and Matching
You should use a case-insensitive regular expression using the re.I flag to do your matching. For example:
...
5
votes
News API in Python - Take II
Type hints
I like the usage of type hints for your functions. However, the return hint
looks wrong for:
def clean_query(text: str) -> str:
The function always ...
4
votes
Transform dataset coordinates from Lambert Conformal Conic projection to WGS84
size of significand
has high memory demand
I'm only seeing 1.5 MiB for each of the pair of grids;
sys.getsizeof(lon_grid) reports 1_473_416 bytes.
You don't have ...
4
votes
Transform dataset coordinates from Lambert Conformal Conic projection to WGS84
Here are some general coding style suggestions.
Naming
The PEP 8 style guide recommends
using all capital letters for constants. For example:
dx, dy = 0.1, 0.1
...
4
votes
News API in Python - Take II
Session
This may not a big deal since you are using requests at only one place, but using a session has some benefits. You can set all your headers at session level ...
4
votes
Accepted
News API in Python - Take II
Reinventing the wheel
The following loop simply reinvents next.
...
4
votes
News API in Python
Just a high-level comment: A large part of the code consists of rule-based parsing of text (all the string-replace calls). This is extremely brittle (there are lots of cases that you won't cover) and ...
3
votes
Find the nearest school to you
CLI
user_input = input("Enter number and name of street/road ")
The input() function has its place.
But consider ...
3
votes
Find the nearest school to you
Layout
Move the function to the top after the import lines.
Having it in the middle of the code interrupts the natural
flow of the code (from a human readability ...
3
votes
Hackerearth: Counting numbers in an array that are divisible by any 2 numbers
Always assume that coding challenge websites will give you worst case scenarios to test your code. They won't test your code with small arrays of small numbers. They'll give you large arrays with huge ...
3
votes
Guess a Number Game
Observations:
PEP 8 suggests using snake case for function names. A name like GuessNum is appropriate for a class, but a function should be something like ...
3
votes
Parse path string
Movement conflates at least three different things: tokenising/scanning (part of lexing), evaluating, and application of the path to start coordinates. In other ...
2
votes
Beginner python program to get data from string
My review will focus on the parsing logic.
months_of_year and days_of_week should be deleted. ...
2
votes
2
votes
Parse path string
Portability
I realize this question was posted many years ago when Python version 2.x
was prevalent, but now that it is deprecated, consider porting to 3.x.
To do so, it is necessary to add ...
1
vote
Hackerearth: Counting numbers in an array that are divisible by any 2 numbers
Portability
I realize this question was posted many years ago when Python version 2.x
was prevalent, but now that it is deprecated, consider porting to 3.x.
To do so, it is necessary to add ...
1
vote
Python pyautogui used for a 2D game
Layout
There should be blank lines between functions.
The black program can be used to automatically
reformat the code for you.
Comments
Remove all commented-out code to reduce clutter:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
python × 15592python-3.x × 5187
performance × 2368
beginner × 2007
python-2.x × 1235
algorithm × 1210
programming-challenge × 1047
numpy × 755
object-oriented × 728
pandas × 599
game × 552
strings × 490
web-scraping × 429
time-limit-exceeded × 398
tkinter × 357
parsing × 324
csv × 304
django × 302
hash-map × 295
random × 253
pygame × 248
recursion × 245
file-system × 238
regex × 234
reinventing-the-wheel × 225