Skip to main content

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 vote
0 answers
16 views

Flask web normalizer CSV app

I've created a Flask application that processes Excel files uploaded by users. The application reads specific data based on client-specific keywords and generates a CSV file which users can download. ...
Pointless's user avatar
2 votes
2 answers
65 views

BlackJack in python

I began creating blackjack in python; however, I'm looking to simulate it, so I'm thinking I'm going to need to optimize it so that I don't just leave my computer running for three hours waiting for ...
Joseph Beegle's user avatar
2 votes
2 answers
173 views

Tic-tac-toe OOP Minimax Algorithm

I wrote a module that I intend to use in my next tic-tac-toe project. All it is is a class that stores the boardstate along with some methods/properties. The biggest thing is the minimax alg. As shown ...
flakpm's user avatar
  • 43
2 votes
1 answer
122 views

Dial up some obscure stats for the Chutes and Ladders game

Years ago, I wrote some code in Perl for the Chutes and Ladders game. I re-wrote the code here in Python. The code simulates one player in a game to see how many spins of the dial are needed to win ...
toolic's user avatar
  • 3,375
-3 votes
0 answers
48 views

Buckshot roulette, a turn based roulette game in Python [closed]

I have started this game to represent Buckshot roulette. I have been coding in python for maybe 2 months and don't know a whole too much about how to undergo this project. This is what I have so far, ...
Aw3sie's user avatar
  • 1
14 votes
4 answers
2k views

Create a snail matrix

Statement: Create a script that, given an integer \$n\$, create a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern. Example: ...
Dorian Turba's user avatar
6 votes
4 answers
415 views

Optimal Solution for the Four Divisors Problem on LeetCode

I recently encountered the Four Divisors problem on LeetCode and managed to achieve a 100% beat rate with my solution. I'd like to share it with you all and gather feedback on its effectiveness and ...
BrunoBarreto's user avatar
2 votes
3 answers
72 views

Arithmetic practice script in a tkinter window

I wrote a script that gives the user a quick arithmetic quiz and results using a tkinter window. I am very new to programming, and this is also my first time using <...
flakpm's user avatar
  • 43
7 votes
3 answers
939 views

Is this Python/Pygame that draws a maze well structured?

I'm not very confident about this piece of code I created, it basically takes a file like this: ## # ## ## # #B # # # ## ## ## A###### Then proceeds to ...
José Gomes's user avatar
-4 votes
0 answers
26 views

Turning a table with months and days and adding the month with total number of days into a dict for each month [closed]

I am currently working on a Python function that needs to process a dataset represented as a list of tuples, where each tuple contains data about hotel occupancy by month. Specifically, each tuple ...
user282488's user avatar
-4 votes
0 answers
23 views

Request for Assistance with DFS, PMI, and Pairwise Constraints Implementation (Python) [closed]

I've been working on a Python implementation combining Depth-first Search (DFS depth = 2), Pointwise Mutual Information (PMI), and Pairwise Constraints (ML must link and CL cannot link). While I've ...
Zoge13's user avatar
  • 1
2 votes
1 answer
56 views

Python sklearn rolling yearly validation

I am trying to implement a simple modelling pipeline with rolling c.v., making use of the TimeSeries split. The code is provided below with a working example dataset. (please don't pay too much ...
Lucas Morin's user avatar
4 votes
2 answers
292 views

Optimizing Multiple Subplot Visualization and Navigation in Matplotlib

I have implemented a class in Python using Matplotlib for visualizing multiple subplots along with navigation buttons to move between different subsets of data. Each subplot displays a contour plot ...
Cold Fire's user avatar
4 votes
2 answers
160 views

Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS

Attached below, and also as this GitHub gist, is code for a Python class I wrote as part of a personal learning/portfolio project on collaborative-filtering recommender systems via matrix ...
Cosmic Fan's user avatar
-1 votes
2 answers
98 views

Breadth-first search [closed]

there are some problems in this code that I can't think of a solution. It does work for print(real_path,count) but the real thing I want is return real_path,count and for doing this I need to make the ...
tumr's user avatar
  • 51
5 votes
3 answers
307 views

Find highest number of swaps within a set of possible duty swaps with networkx and PuLP

With huge help from Stack Overflow, I have created code which takes possible swap matches with given weights as an input and outputs a set of matches which gives the highest weight with the highest ...
Oehoe's user avatar
  • 53
5 votes
2 answers
714 views

A small REPL in Python

The REPL offers functionality for inserting, deleting, and searching within a red-black tree, along with the capability to generate an ASCII or graphical representation of the tree structure. ...
Harith's user avatar
  • 5,844
8 votes
3 answers
483 views

python cprofile decorator

If you're anything like me and sometimes write pretty slow code... you may end up going back to API's or scripts and wanting to profile an endpoint/method to see what is taking so long - so I can ...
Feynboy's user avatar
  • 81
8 votes
3 answers
838 views

Split String Function Implementation in Python

For learning purposes, I am trying to implement Python's built-in function split. I am new to Python, and I know that str.split ...
JimmyHu's user avatar
  • 4,748
-1 votes
2 answers
123 views

Drayage Webscraper: Limited to table structure

This is my first working scraper. I'm sure a lot can be improved. My biggest question is how can I better specify what data to pull? All the data I'm currently grabbing is needed, but I couldn't ...
wigglesthe3rd's user avatar
5 votes
1 answer
104 views

Making sklearn's decision trees easier to traverse

scikit-learn's decision tree structure is difficult for me to navigate. I would prefer to have functionality like tree.left, ...
Steven Gubkin's user avatar
3 votes
0 answers
48 views

Text-Based Multiplayer RPG Engine using Flask & React

As a final project for a software engineering bootcamp, I decided to make a text-based multiplayer RPG game engine. Using Python, Flask, & Flask-SocketIO for the backend and React & TypeScript ...
Thomas Makurat's user avatar
10 votes
3 answers
1k views

Function that returns activation function, as well as its derivative

I have the following function that returns one of several functions along with their derivative for training neural networks. Can this function be improved and made more pythonic in any way? Are there ...
Atharva's user avatar
  • 103
4 votes
1 answer
121 views

Repetition-Limited Multiset Coefficient function

This is a simple multiset coefficient calculator in python, that will calculate both standard multiset coefficients, as well as multiset coefficients with repetition limits, used initially as part of ...
Lee Davis-Thalbourne's user avatar
-2 votes
1 answer
57 views

Code that loops through a df and joins two seperate dataframe and sink into delta lake, how do I make it run faster?

I have two dataframes: Budget and Forecast. For those dataframes, I'm trying to create snapshot record by joining with temp table snapshot_to_collect for loop. I'm ...
user282159's user avatar
3 votes
2 answers
280 views

Text-based blackjack in python

This is code for a text-based game of Blackjack. I would also like advice on how can I implement a betting system in this program. For example starting with an amount of chips and choosing how much of ...
vaun's user avatar
  • 31
12 votes
2 answers
1k views

Space shooter game using pygame

I have made a space shooter game in pygame with over 800 lines of code (including blank lines). The aim of the game is to kill all of the ships in the game. You start with a small spaceship and one ...
coder's user avatar
  • 121
1 vote
0 answers
55 views

Django Google Authentication App Using OAuthlib and DRF

Context I've been working on a Django-based Google Authentication application, designed to manage OAuth authentication without relying on libraries such as ...
Grajdeanu Alex's user avatar
3 votes
1 answer
81 views

Multiline string concatenation

Problem Description Printing the result of adding two numpy arrays together is very ugly. Here we will use these numpy arrays as an example: ...
mikeLundquist's user avatar
2 votes
1 answer
50 views

Python REST API using FastAPI

...
Sayaman's user avatar
  • 415
4 votes
1 answer
64 views

Centre of mass based TSP solution (2)

I updated the code to a working state. My previous question. Even if this code working I wonder if I can write this code in a more efficient way. Maybe less for loops Etc. ...
tumr's user avatar
  • 51
1 vote
1 answer
35 views

Multi-threaded Error Handling Data Fetching Script

I've been working on a Python script that fetches student data from an API using multiple threads for concurrency. The script retrieves both student information and prospectus data and saves them to ...
K. Cinches's user avatar
2 votes
2 answers
84 views

Checking file header for magic number in Python

I wrote this to check files for successful compression with LZ4. Any advice is welcome. Particularly regarding raising exceptions and error handling. ...
voices's user avatar
  • 767
3 votes
3 answers
171 views

Converting a dict to a list + ID

I wrote this code: PROJECTS_LIST = [ project if not project.update({"project_id": project_id}) else None for project_id, project in PROJECTS.items() ] ...
UCYT5040's user avatar
  • 151
4 votes
1 answer
108 views

Optimising Graphed Rewards

Relates to this and this. Simply put; I want to be able to distribute a total reward among network, where the distribution diminishes according to the depth of the network but the total sum of ...
Bob's user avatar
  • 149
0 votes
1 answer
104 views

Centre of mass based TSP solution

This is the code that I tried to approach to the traveling salesman problem in a new way. As you can see, it does not give such great results. Can I get this idea further, or should I quit to ...
tumr's user avatar
  • 51
2 votes
3 answers
142 views

Creating a search function

Write an efficient function in the Python language called SmartSearch. This function will receive a sorted arr array of integers of size \$n\$ containing at the ...
SHOVAL's user avatar
  • 21
2 votes
3 answers
553 views

Extract data from poorly formatted phonebook

The Problem John keeps a backup of his old personal phone book as a text file. On each line of the file he can find the phone number (formated as +X-abc-def-ghij where X stands for one or two digits),...
Vessel's user avatar
  • 83
5 votes
3 answers
1k views

URL shortener using Flask

...
Sayaman's user avatar
  • 415
2 votes
1 answer
45 views

A selenium web scraper to package NBA data

I'm building a selenium web scraper for basketball-reference.com that takes a player name and returns data in either a JSON format or Pandas DataFrame object. The class in question is one of many that ...
BluffShove's user avatar
2 votes
4 answers
659 views

Adding Node to Linked List

I've been programming for 3 months now, and I've just come across Linked List, and I'm not gonna lie, I've been struggling a little. I wrote this code to practice on Linked Lists. The purpose is to ...
fraber's user avatar
  • 179
4 votes
4 answers
1k views

Creating an O(n) algorithm for an array of integers

To avoid plagiarism in my university, I am going to modify the problem. Henry likes to jump from building to building. The heights of each building are given as a list of H numbers. We also number ...
Duckycodes's user avatar
2 votes
2 answers
308 views

Minimal AlphaGo algorithm implementation for game 2048, connect4

I'm writing tutorial code to help high school students understand the MuZero algorithm. There are two main requirements for this code. The code needs to be simple and easy for any student to ...
user281935's user avatar
7 votes
1 answer
960 views

Python Breakout game

I came from C# background with strong OOP approach. I've decided to learn Python and Breakout game is a way to cover the basics of Python. I'll be really glad for any feedback and general opinion ...
NeverDoomedEnough's user avatar
7 votes
1 answer
242 views

Colorful Subgraph Dynamic Programming Solution and a Naive One

Given a graph \$G(V, E)\$ with vertices \$V\$ and edges \$E\$, where each vertex is associated with a single color from a set of colors \$C=\{1, 2, ..., k\}\$, we define the following problem: Problem ...
FluidMechanics Potential Flows's user avatar
4 votes
1 answer
118 views

Finding the earliest time we can schedule

We have a list of \$j \in \{1,\ldots,N\}\$ jobs with a processing time \$p_j\$ and a demand \$d_j\$ between 0 and 1. These are real numbers. Jobs require the fixed demand over the entirety of their ...
Titan's user avatar
  • 41
4 votes
2 answers
287 views

Simple version of NEAT

I have wrote my own simple version of NEAT and want to improve the code for mainly performance (training and runtime of a generation). This simple version of NEAT aims to perform somewhere near as ...
coder's user avatar
  • 121
2 votes
3 answers
114 views

Further developing calculating crude death rates and age-standardised death rates

This script is a further development of Finding crude death rate and age-standardized death rates from data. In reflection to the kind reviews I created a module for the data; saved the data in ...
Attila Vajda's user avatar
4 votes
1 answer
128 views

Longest spell to cast from pages of spellbook follow-up

This question is from the PCTC 2022 R2 Past Paper and is a follow-up on my previous question. Previous question I have implemented several solutions suggested, such as creating an array with pages ...
helielicopter123's user avatar
3 votes
2 answers
171 views

Finding crude death rate and age-standardized death rates from data

How can I improve this code's readability and function, for finding crude death rate and age specific death rate? Given are the death rates from chronic pulmonary obstructive disease in 2019, the ...
Attila Vajda's user avatar

1
2 3 4 5
310