New answers tagged python-3.x
0
votes
Determine a diver's table and schedule based on depth and duration
Use better program structure
If your code is starting to look repetitious, you can think about subroutines.
In this application, you are interpreting a table according to a set of rules. Since your ...
2
votes
Small shopping cart application - Solid Principles and Clean Code
I see no need for abstract classes here - there are no alternate implementations.
This string:
" Name: %s \n Price: %s \n" % (self.name, self.price)
has ...
5
votes
Check how many days a country has been independent
Delete all of your comments. None of them make the code more obvious than just reading it.
strftime is unused so don't import it.
Consider using a dictionary of ...
1
vote
Compare files by name in two folders A and B and delete duplicates from folder A
The first "duplicates" line should read
duplicates, *_ = groups = [files[0] , files[1]]
my extended code
move to trash - instead of delete
...
2
votes
-1
votes
Accepted
Forecast experimental results based on temperature
Your data are misshapen. Rather than having a separate Temp_ column per... what are those (10, 15, etc.)? Temperatures? There should be an index level per ...
3
votes
MATLAB / vs Python np.linalg.solve, heat diffusion
Can you please tell me why Python is an order of magnitude slower for only even linear solve?
Answering this generically is perhaps a little off-topic for review, but: first, it's important that we ...
2
votes
Removing medications older than 180 days ago from a list
Bugs
The code has at least two bugs.
The first is when two adjacent list items are more than 6 months old, the second one will not be deleted. This occurs because when an item is deleted, the rest of ...
3
votes
Comma code project from "Automate the Boring Stuff with Python"
Don't use try-except blocks casually or excessively. You don't need them in
the current case. And when exception handling is truly needed, you should
restrict its use to the narrowest possible scope --...
3
votes
Accepted
Credit Card Validation Check (Using Luhn's Algorithm)
Your program and functions are structured ineffectively. You have some code
at the top level (collecting user input and converting it to numbers), then
most of the ...
3
votes
Removing medications older than 180 days ago from a list
Use a list comprehension! When constructing lists in python by looping through others lists, its a lot more visually de-cluttered (not necessarily more performant) to just use python's list ...
-1
votes
Removing medications older than 180 days ago from a list
Depends on how much you care about performance. If you really care, don't use Python. If you kind of care, use Pandas in Python.
I cannot speak to how you load your data in Pandas because you haven't ...
3
votes
My 1 Week Python Journey — A Quiz Game that I made in Python
8-10 days aren't much and it gets the job done without any obvious errors so yeah that's ok.
The efficiency of the program is mostly a concern if you're doing stuff that is computationally heavy and ...
2
votes
Accepted
Get some cryptocurrency rates from coingecko api
First, PEP8 suggests using snake_case instead of camelCase for regular variable names, so you should rename those.
...
5
votes
How can I make my Pygame Tic Tac Toe game better?
These points are in order of how I went through your program. They are not ordered in matter of importance.
Your code is suspicious from the start:
...

Mast♦
- 12.7k
3
votes
Accepted
Multi stage Dockerfile for eccode compilation
Instead of a COPY + RUN tar, you can get Docker to do the extraction for you by using ADD, ...
0
votes
Accepted
Speeding up row insertion to Pandas DataFrames
Without knowing what info['participants'] looks like, I've made this assumption.
As others have mentioned it would help the reviewers if you could provide a small ...
0
votes
3
votes
Multi stage Dockerfile for eccode compilation
Minor: tar -xzf eccodes-2.24.2-Source.tar.gz can simply use tar xf as the z is implied by ...
12
votes
My 1 Week Python Journey — A Quiz Game that I made in Python
How is my progress so far (~8-10 days of learning)?
Progress is non-linear, and technical learning is a long, long road (years-scale, not days-scale). So it's impossible to assess like this, but &...
16
votes
My 1 Week Python Journey — A Quiz Game that I made in Python
Welcome to your journey in programming and in Python, I think that these 2 main concepts will help you improve to the next level:
Functions as computations with an output rather than control flow ...
1
vote
Guessing the Number Game
As you said, you are using PyCharm for writing Python code. Using this IDE, it only takes a single keyboard shortcut to make your code conform to large parts of PEP 8, which is the Python style guide.
...
1
vote
Accepted
Simple backup script with file removal after 7 days
For many of your file manipulation operations prefer pathlib over os.
You can pull in your filename formatting including time to ...
2
votes
Guessing the Number Game
Underlining the structural advices of AJNeufeld:
Structure helps to break down logic and express this organization visually, so that your code gets easier to read.
I will try to illustrate the ...
3
votes
Accepted
Weighted Union-Find class
Documentation
Docstrings are for users of the class. Docstrings should explain what is being done and returned. Currently your docstrings explain how it is being done, which should be comments.
...
1
vote
Coin partitions
The readability is fine. If you cut out the documentation it's about 15 lines long, and short is almost always readable.
Replace coins.sort with ...
1
vote
3 dimensional python battleship game
The biggest problem with this code is readability. The actual program looks well-structured (good functions, reasonable use of classes, use of appropriate libraries, etc).
There are a large number of ...
7
votes
Guessing the Number Game
White Space
Your code needs some.
Specifically, blank lines between logical sections of code.
between imports and function definitions
Between function definitions
After the last function definition ...
0
votes
12 hour to 24 hour time conversion
In production code you would never manually parse a datetime like that. Instead you would use a round-trip through the datetime built-in:
...
10
votes
Guessing the Number Game
Congrats for starting on your journey! Python is a great start to get into programming. And you got your very first project working! I can see that you used the basic elements of programming languages,...
1
vote
Accepted
12 hour to 24 hour time conversion
Program structure
timeconversion is not a very descriptive function name. What is it converting from, and what is it converting to? I suggest ...
1
vote
Fantasy game inventory — Ch. 5 Automate the Boring Stuff
I'm doing this in June 2022 but I don't think the problem asks for plurality for the values. In the example given, all the values are worded singularly. However if you want to go one step further to ...
0
votes
Program for creating custom directory listings
You care about state of the art: that's good! But CGI and state of the art do not go in the same sentence.
You're writing for integration to a specific server, Abyss, whose Python support explicitly ...
1
vote
Accepted
Design Tic Tac Toe Interview Problem [Python 3]
This is an incomplete review up to the function TicTacToe.turn
Re: ...
6
votes
Determine a diver's table and schedule based on depth and duration
Pandas was built for this kind of thing, and you can likely get your 700+ line program down to 30 lines of Python and a CSV file. You need to eliminate all of the repetition in your code, pull out the ...
4
votes
Accepted
Design Shopping Cart System Interview Problem [Python 3]
Broadly speaking this does a lot of things right: self-written exceptions, (the start of) type hinting, overridden __str__, etc.
...
5
votes
Implementation and Testing of Exponential Search for scenario where we search the same array/list many times
(Exponential Search is an improvement over binary search
where the target can be expected to be close to some starting point.)
class ExpSearch does not have a ...
3
votes
Accepted
Adding string to a text file without duplicates
You could make some improvements:
Open the file just once in read+update mode.
Instead of current_id_list, use a set, which can test whether an item is one of the ...
2
votes
One of my first Python projects - an adventure game
This could be a place to implement a state machine. For such simple program, I would use globals to store the game state. (Unless you want to host multiple sessions at once in one process.) I would ...
3
votes
One of my first Python projects - an adventure game
As already mentioned by others, the branch conditions will get out of control quickly. It may be more suitable to encode the storyline in a separate file, such as a JSON file. Therefor we can identify ...
7
votes
One of my first Python projects - an adventure game
Since you don't wait between prints, you can join some of them. Use triple quotes to extend a string on multiple lines (can be used for comments too)
and \n to make a line break.
...
1
vote
One of my first Python projects - an adventure game
Just a little tip
on this line :
start = input("Do you wish to begin your adventure? ").lower()
When I tried your game, I just hit enter and it ...
10
votes
1
vote
One of my first Python projects - an adventure game
Right off the bat, instead of strings maybe it'd be better to prompt your users to input the option number instead. It'd probably be cleaner, less prone to user error and allow you to run a Switch ...
4
votes
Accepted
Calculate the number of people occupied at each time interval
Generally, at the edge of your program you shouldn't be entering datetimes as timestamp numeric literals, but as human-legible datetimes. On the inside of your program, you also shouldn't be ...
1
vote
Password policy with regex and zxcvbn
Elevate the data that drives the code to the status of named constants.
Among other benefits, this simple change will support any efforts you might
make to subject the code to automated testing (...
9
votes
Measure the total runtime of a function in a project
The already accepted answer by Dair is better than what I am about to write here, however I think there is didactic value in trying to improve the code as written, so consider this a supplementary ...
2
votes
Accepted
Calculates delivery charges and number of deliveries
Python has built-in support for showing localised currencies; you might as well use this. It shows to the nearest pence so you don't really have to use Decimal for ...
4
votes
Password hashing for safe storage with Argon
Argon2 is a decent choice of hash. Well done for following the most important rule of cryptography, and letting someone else design and implement the cryptography!
There are a few minor style things ...
14
votes
Accepted
Measure the total runtime of a function in a project
Adressing the question:
Is there already a solution like this in the standard libs?
Unless I am misinterpreting what you want exactly, there are profiling tools available in the standard library.
...
Top 50 recent answers are included
Related Tags
python-3.x × 5095python × 4930
beginner × 794
performance × 607
programming-challenge × 428
algorithm × 310
object-oriented × 270
web-scraping × 201
numpy × 168
game × 167
pandas × 156
time-limit-exceeded × 136
strings × 127
tkinter × 127
reinventing-the-wheel × 100
beautifulsoup × 83
parsing × 82
tic-tac-toe × 81
csv × 79
random × 78
file × 71
hash-map × 70
file-system × 70
mathematics × 70
regex × 69