Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
5 views

unexpected indent error in while loop ( in python) [closed]

hi I am writing a code to integrate schrodinger equation using Numerov method, how ever in one code block I am having "IndentationError" which says 'unexpected indent'. here is my code below,...
user avatar
  • 1
0 votes
0 answers
14 views

Singleton Design pattern: what is the best implementation [closed]

I can write the 2 following implementations but was wondering what is the best implementation: the first one require class methods and class variables (common to the instances which are the same). <...
user avatar
  • 273
-1 votes
0 answers
11 views

Please correct any misunderstandings ive made when commenting what this code does [closed]

Hi im studing zed shaws learn python the hardway, he says i must go and read other peoples code and comment what i think it does please can someone review it for me and tell me if i've misunderstood ...
user avatar
2 votes
1 answer
27 views

Find perfect squares within a given range

I managed to make this work without breaking the program if you enter some weird numbers in the range. The thing is I know this could have been done simpler and smarter. I can't really see how right ...
user avatar
0 votes
1 answer
17 views

An algorithm that minimizes the number of ingredients necessary

I am working on a code that will minimize the number of ingredients necessary to make some dishes. Each dish can be prepared in an arbitrary large number of ways, with combinations of two ingredients. ...
user avatar
1 vote
0 answers
26 views

Integration loop over multiple doping and temperature levels

I want to perform some calculations on a large dataset. The code can be found below, where I want to calculate the values for 'results_nr' over a large loop (1000 x 910) values. Can you help me out ...
user avatar
1 vote
0 answers
17 views

Python - dictionaries and making a list of student enrollments

I'm new at Python and I have to make a list of student enrollments and use dictionaries within a class. I want to manage a list of exam enrollments. To do this, it is necessary to create the ...
user avatar
0 votes
1 answer
15 views

Treat a list by generating a dataframe and sending the data to function via multiprocessing

To collect the list with the data from an API, I need to do these steps: ...
user avatar
0 votes
0 answers
12 views

Perform data cleansing on objects that pass through a data pipeline [closed]

I have a data pipeline where I need to perform data cleansing on objects that pass through the pipeline. As a simplified MRE, the code below creates an example object and then simulates a data ...
user avatar
  • 133
4 votes
1 answer
161 views

Converts image from one type to another

This script first looks through a specified folder path for image files that have a given extension and removes any periods that might be in those file names. It also adds those sanitized file names ...
user avatar
1 vote
0 answers
14 views

Database Repository Class Using the Decorator Pattern

I have a base repository class that's using AWS DynamoDB, and I have also implemented a class named StocksRepository I'm wondering if I should create a StocksRepositoryWithLogs and ...
user avatar
  • 21
0 votes
2 answers
24 views

Decrement from an array of integers equally for all elements > 0

There are x distribution centers each with y number of products. Each day only an equal amount from all x distribution centers with remaining product can be shipped. Calculate how many days it would ...
user avatar
  • 111
2 votes
1 answer
32 views

Find the column number in a spreadsheet according to the letter that identifies it

Google Sheets maintains an identity for each column that follows this pattern: col 1 = A col 26 = Z col 27 = AA col 52 = AZ To know the column number according to ...
user avatar
0 votes
0 answers
42 views

Is the given code optimized ? Can it be optimized? [closed]

I have a dashboard where I have to show the Charts and graphs for weekly sales(7 days before including today) , monthly sales(12 months before including this month) and profit/loss got in 7 days with ...
user avatar
1 vote
0 answers
32 views

Program for monitoring file in Combined Log Format

After encountering a suggestion that monitoring a log file for a webserver could allow for the implementation of automatically analyzing and handling of certain events (that might require altering ...
user avatar
1 vote
0 answers
57 views

Smallest interval whose sum exceeds a threshold

In a non-negative 1D array x, we wish to find the shortest slice such that x[start:end] > threshold, with constraint that <...
user avatar
3 votes
1 answer
145 views

Applying a cost function to a string based on a pattern string

I have a cost function Cost_Func(pt,STRING) that calculates value in a specific way based on the given pattern string pt and ...
user avatar
  • 133
2 votes
7 answers
2k views

Print a list of license plate numbers of all cars that went over the speed limit, as well as the average speed of each of those cars

I wrote a working code and was wondering if it could be shortened as I saw a lot of similarities in my loop and if statements. I hope it's possible as I want to make it a bit cleaner. I had to print a ...
user avatar
2 votes
1 answer
20 views

Matching corresponding masks of objects between 2 images

Here is a program that processes 2 grayscale images. Both represent the position of objects, in the form of multiple masks per image. Each mask is a shape with one color delimiting it, with 0 (or ...
user avatar
-2 votes
0 answers
13 views

Random number generator repeats issue? [closed]

So essentially, I am trying to make a program where you enter three numbers between 1-10 and the bot will spit back a corresponding seed which matches the values of your inputs (I am bored, that's why ...
user avatar
  • 1
0 votes
1 answer
65 views

Optimizing a program that checks through a very large set of permutations

I'm not sure if this is the correct place for an optimization question like this, but I'm not even sure where to start looking. So here it goes. There's this game I play that has very simple rules. ...
user avatar
1 vote
0 answers
17 views

Permutation of linear models with Python

Similar to my previous post in R All permutations of a linear model given all predictors, I have attempted a Pythonic version. However, a few issues that I have with my version is that I cannot select ...
user avatar
4 votes
2 answers
492 views

A simple spaceship game

How could I improve this code? It's a little game. If you run it, instructions will appear. In particular, I'd like to know whether I can make it considerably shorter any trick :) ? whether I can get ...
user avatar
1 vote
0 answers
17 views

Minesweeper using Tkinter

So, I have completed a Minesweeper program in Python using Tkinter. A few questions: I feel I should convert this to Object-Oriented Programming. Any starting tips? Expanding on the above, I have way ...
user avatar
  • 147
0 votes
0 answers
36 views

Television and channel modelling [closed]

I wrote a simple project to train my beginning knowledge of OOP. My class represents a Televisor that has two types of channel list: the first one is global, that's applied to all objects of my class ...
user avatar
0 votes
0 answers
41 views

Web Scraping: finding a particular content and taking an action for multipule pages

Summary: the whole code is given at the bottom the problem (or say main concern) is described hereinbelow. The code scrappes the website goes through various pages and finds particular content to ...
user avatar
  • 231
3 votes
0 answers
54 views

Decorator implementation around xarray.open_dataset

If you would like to download some grib data for yourself, the script below will pull girb data from the google api over a date range at an hourly interval. Extract some hrrr grib2 data ...
user avatar
-2 votes
0 answers
18 views

Python while loop - How to print last value without tab [closed]

I am working to create a program that creates a hailstone sequence and I'm nearly there except my last value is printing with a tab after it. I can't figure out how to fix my code below to not have a ...
user avatar
3 votes
1 answer
130 views

Resize image, blur image and overlay image

This code has the function of removing worthless borders from the original image and then: Generate a 1080x1080 image (Instagram default) to be used as a blurred background. Generate an image with a ...
user avatar
4 votes
1 answer
103 views

Check how many days a country has been independent

I have been using a website called 'CSNewbies' to learn Python and one of the tasks was to create a way for a user to check how many days a country has been independent. The countries are limited to ...
user avatar
6 votes
1 answer
236 views

Check stock status at a retailer

I am learning Python and wrote this code to check (every 10 mins) whether a product is available at a retailer, since it usually runs out of stock pretty quickly. It's working as expected, but can ...
user avatar
  • 61
3 votes
1 answer
105 views

Small shopping cart application - Solid Principles and Clean Code

I've recently had a technical interview where I had to identify code smells and refactor an existing code by applying the SOLID principles and implementing unit tests. It is a small shopping cart ...
user avatar
-1 votes
0 answers
16 views

Beginner looking for Critiques! Formatting an Excel for Tableau using Openpyxl [closed]

I just finished writing a script in openpyxl to automatically format a dataset so it can be placed into Tableau. The script is running and working as intended but I know there are some things that can ...
user avatar
0 votes
0 answers
39 views

Deterministically hash dictionary

I need to compute a deterministic hash for a JSON-serializable dictionary. This answer almost does the job, but there are a few problems. If dict1 == dict2 then I ...
user avatar
-1 votes
1 answer
54 views

Forecast experimental results based on temperature [closed]

I would really welcome any hints on making this code more concise please. In this example we have some experiment results. For each planned experiment We have predicted results based on 4 temperatures ...
user avatar
  • 3
0 votes
0 answers
72 views

Best design for a generic reader

My goal is to propose a generic interface to read all kind of document, without bothering of file extension (reading word, pdf, etc ...). First Implementation: My first attempt was to implement: a ...
user avatar
  • 273
0 votes
1 answer
48 views

Optimization using a differential evolution technique, ideally with a million iterations

I'm working on an optimization code using differential evolution to solve. However, it is taking a long time to get the solution. See that I have a variable called number_of_iterations that must equal ...
user avatar
4 votes
2 answers
59 views

Python Tkinter UI Pattern Password Code

This post is less of a question and more of a hope for people to see my code which I know is far from great and give me some direction or simple tips on improving the quality of it. Normal Stud: ...
user avatar
  • 41
1 vote
2 answers
70 views

Comma code project from "Automate the Boring Stuff with Python"

...
user avatar
2 votes
1 answer
58 views

Credit Card Validation Check (Using Luhn's Algorithm)

...
user avatar
  • 333
1 vote
3 answers
51 views

Removing medications older than 180 days ago from a list

I have the following code which removes a dict from a list of dicts in Python based on ...
user avatar
  • 360
1 vote
0 answers
56 views

Renaming keys in a Dict[str, Any]

Given a Dict[str, Any] and a mapping of "key paths" to new names, produce a new dict in the shape of the original that ...
user avatar
  • 111
1 vote
4 answers
86 views

Beginner Python program assignment: calculate the total number of bugs collected in a week using a while loop

Beginning of program assignment has a bug collector input the amount of bugs collected each day of the week then outputs the total number of bugs in a print statement. My professor has forbid us from ...
user avatar
  • 11
2 votes
0 answers
35 views

Python program for the Longest Substring Without Repeating Characters

I write my Python program below for this Leetcode problem: Given a string s, find the length of the longest substring without repeating characters. Example 1: ...
user avatar
1 vote
0 answers
31 views

Hashing service for files or directories on a generic filesystem [closed]

my program requires a hash to be generated for files and folders for data integrity between transfers and file system events (if hash is different, file is not ready). For data integrity, I wish to ...
user avatar
2 votes
1 answer
48 views

Clear output line in terminal after use for countdown (different length strings)

The method to overwrite the same line is well known and I use it for countdown, but what about when the next output string has a different size and will be generated by a single print? That's the ...
user avatar
15 votes
3 answers
3k views

My 1 Week Python Journey — A Quiz Game that I made in Python

I started my Python Journey almost a week ago from now. I had been following a Youtube tutorial earlier, but switched to Harvard's CS50P instead. I decided on making a little Quiz Game with my ...
user avatar
  • 333
2 votes
1 answer
43 views

Get some cryptocurrency rates from coingecko api

I'm currently learning some aspects of PEP8 and Python programming in general. Could you please code-review this little piece of code for me? I would be glad to hear any, even the smallest comments, ...
user avatar
  • 23
3 votes
1 answer
47 views

Crawler/scraper for soccer match results

I wrote this code some time ago as part of the web-scraping learning. Every now and then I find mistakes in it, as well as I have doubts. Feedback please, is this code compliant with the common best ...
user avatar
5 votes
3 answers
304 views

Translating dictionary keys in complex nested Python structures

This is an actual work problem we had to solve. Put simply: given a structure (e.g. nested dictionaries) and a mapping of old dictionary keys to new ones, produce a new structure that is anatomically ...
user avatar
  • 51

1
2 3 4 5
294