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
2 votes
1 answer
12 views

Faster Mathematical Calculation in List Comprehension

I have a cost function Cost_Func(pt,STRING) that calculates value in a specific way based on the pattern string pt and main ...
1 vote
0 answers
9 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 <...
3 votes
3 answers
39 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 ...
0 votes
0 answers
19 views

Prints the license plate numbers of all cars that are still between the two sensors - easy, beginner

I made a code that prints the license plate numbers of all cars that are still between the two sensors. The first line contains the maximum speed (in km/h) for the road that the detectors are placed ...
1 vote
0 answers
15 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 ...
1 vote
0 answers
8 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 ...
-2 votes
0 answers
12 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 ...
0 votes
0 answers
36 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. ...
6 votes
3 answers
6k views

Find diagonal positions for bishop movement

In a chess board, I need to find the diagonals a bishop can move on, and more specifically, the coordinates of those squares. So, given a grid of any size and a position in that grid (expressed in ...
2 votes
1 answer
216 views

Contiguous memory allocation using first-fit algorithm

This project I'm dealing with will read the size of free memory segments and size of processes from a text file and then will try to allocate a memory partition for each process using the first-fit, ...
5 votes
3 answers
109 views

Python 3 Multi-connection downloader

I have written a fully functional simple command line multi-connection downloader, written in Python 3, using just threading, ...
2 votes
1 answer
3k views

Predicting random numbers based on past output

I've been working on a program to predict random numbers based on previous digits. However, I only get access to numbers from 0-53 inclusive, and one only comes every 30 seconds or so, therefore ...
4 votes
2 answers
474 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 ...
0 votes
0 answers
35 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 ...
1 vote
0 answers
16 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 ...
5 votes
0 answers
131 views

@lazylist - Converts a Python Generator to a List without evaluating every element

I made a LazyList class that can wrap an iterable (list, generator etc.) and turn it into a MutableSequence (like ...
7 votes
3 answers
1k views

Thread-safe memoizer

I have searched around but I was not able to find a complete implementation of the memoize pattern in a multithreaded context. It's the first time playing with thread synchronization. The code seems ...
0 votes
0 answers
71 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 ...
3 votes
0 answers
40 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 ...
23 votes
3 answers
4k views

Financial website scraper

I wrote the code that would scrape Finviz for tickers and href that attach to the ticker. I tested with multi-page as well as one page. I'm new to Python ...
7 votes
2 answers
462 views

Finding solutions on GitHub and Stack Overflow

The first part of the code opens Chrome and navigates to GitHub. If I don't find my solution, I open a new tab with ctrlt. Then my code goes to Stack Overflow and searches there for solutions. ...
3 votes
1 answer
710 views

Scraping data from a table in python

I'm new to python, and after doing a few tutorials, some about scraping, I've been trying some simple scraping on my own. Using BeautifulSoup I manage to get data from web pages where everything has ...
0 votes
0 answers
39 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 ...
1 vote
1 answer
1k views

Lo Shu Magic Square (Python)

I wrote a python program to find if a matrix is a magic square or not. It works, but I can't help feeling like I may have overcomplicated the solution. I have seen other implementations that were a ...
3 votes
1 answer
126 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 ...
4 votes
1 answer
100 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 ...
2 votes
1 answer
99 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 ...
-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 ...
5 votes
4 answers
12k views

Preprocessing steps to follow while cleaning and extracting text data from tweets

I have a dataset of around 200,000 tweets. I am running a classification task on them. Dataset has two columns - class label and the tweet text. In the preprocessing step I am passing the dataset ...
6 votes
1 answer
228 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 ...
4 votes
3 answers
78 views

python Chatroom/Codehelp through the terminal

I created a system that allows individuals to ask questions about code, and chat. I wanted to make this system smaller and better because this is easy to bypass for some reason. The modules/packages I ...
-1 votes
1 answer
53 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 ...
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 ...
4 votes
4 answers
6k views

Compare files by name in two folders A and B and delete duplicates from folder A

I wrote my very first Python program to answer a Super User question. I'm wondering how the application can be rewritten to make it as pythonic as possible. Unit test ...
6 votes
1 answer
100 views

Implementation and Testing of Exponential Search for scenario where we search the same array/list many times

Exponential Search is an optimization over binary search. Conceptually, when searching for a number target in a list of numbers ...
4 votes
1 answer
1k views

Login system using bcrypt and MySQL, to be used for any future projects

Main function will ask what the user wants to do. LoginSystem class will handle the sign up and login process as well with the checking if password is right. passwordHashing will use bcrpyt to salt ...
-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 ...
1 vote
2 answers
68 views

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

...
0 votes
0 answers
35 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 ...
4 votes
2 answers
56 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: ...
1 vote
1 answer
152 views

MATLAB / vs Python np.linalg.solve, heat diffusion

I am solving a simple 1D steady heat question using spectral method. I am a long time MATLAB and Mathematica user and trying to learn Python. I compare only linear solving times and Python is way ...
22 votes
1 answer
28k views

Check if a directed graph contains a cycle

I am trying to optimize execution time of this function which detects cycle in a directed graph: ...
-3 votes
0 answers
30 views

Whats the best way to pass many cli arguments between multiple functions in python? [closed]

I write a lot of cli tools in python. Most of my tools have something like this to get arguments: ...
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 ...
1 vote
3 answers
48 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 ...
2 votes
1 answer
57 views

Credit Card Validation Check (Using Luhn's Algorithm)

...
2 votes
1 answer
343 views

PHP / Laravel - Using Python to image manipulation

I have a simple job class in Laravel, that will do the following: Get all the images in a folder /original Perform some image manipulation on each image Save each ...
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 ...
2 votes
0 answers
32 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: ...
14 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 ...

1
2 3 4 5
294