Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

0
votes
0answers
6 views

Generate a dummy XML from a given XSD in python

I have the following XSD https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/sample-xsd-file-customers-and-orders1 and I want to generate a dummy xml file which is a valid ...
0
votes
1answer
7 views

Thread-safe singleton cache (Python)

In a service I'm developing I'm using three cloud services (five if you count additional two streaming services I have to create that are used by those cloud services in turn) and to orchestrate bits ...
0
votes
0answers
11 views

Omit pronoun/common words when searching in Python

I have a python program to count most appearing words in a file. Now I want to omit most common words from the file. I have written 2 program for this. How can combine them or call internally? ...
2
votes
1answer
34 views

Game AI to slow to work

I have written some python code to play this scratch game. But it is to slow to function correctly because each frame if it clicks, it takes a screenshot of almost the same thing like this ...
3
votes
3answers
421 views

First Python program: Snake

I've started learning Python yesterday with the intention of studying machine learning. Before this, my experience with programming was exclusive to my first semester where I had a C course. I ...
1
vote
0answers
23 views

Outlook email rules and attachment downloader in Python

I wrote this script to replace a VBA script for mailbox management that was in place before. Essentially, I have an Excel sheet in which the rules are defined. These have to be loaded and applied to ...
0
votes
0answers
30 views

kmeans image clustering

I am a beginner in Python development, I have implemented kmeans. But it takes too long to run to completion. How can I optimize my code? ...
0
votes
0answers
25 views

Generating a bitboard with all possible bishop moves [on hold]

I am in the middle of programming a chess ai. I have run into a problem when trying to calculate all possible diagonal moves for the bishop. I think the problem lies within the function: ...
-1
votes
0answers
13 views

Transform a “template” class as a abstract class [on hold]

What is a proper way to define Feature class as an abstract class with ABC and abstractmethod...
2
votes
1answer
29 views

Python 3 minesweeper tkinter game

I have just finished my minesweeper game using tkinter and would like to know how I could improve my program. ...
-3
votes
0answers
14 views

Python: cycles and indices [on hold]

Write a function which receives an "L1" list of integers and returns a list "L2", of the same length as "L1", whose generic element L2[i] is equal to the first major element of L1[i] present in "L1". ...
2
votes
1answer
19 views

Print out numbers of increasing distance from center value in Python

I am trying to print out numbers by increasing positive and negative values around a center number, and I don't think I've found the best way. For example, say I want to find what number in a list my ...
6
votes
1answer
31 views

Forcing the user to choose from a set of options (in Python)

First Code Review request =) I wrote this after making several projects that required a user to pick an option. I wanted to have a set way of forcing that choice in all of my projects. The module also ...
1
vote
2answers
33 views

Work out largest prime factor of a number

I am trying to get better at problem solving, so I am going through challenges on Project Euler. Problem: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
1
vote
1answer
20 views

Django functions to sanitize URL, return welcome message, redirect, compute HMAC, and manage profile picture

I wrote this code to to perform the following: I will remove the "spaces" within the url. Return welcome message. Redirect the user to different url. Compute HMAC for the request. Return and revoke ...
3
votes
1answer
32 views

Hamming Distance in Python

I was solving this Leetcode challenge about Hamming Distance. Would love feedback on my syntax and code style. Here's the challenge description: The Hamming distance between two integers is the ...
0
votes
1answer
31 views

Predicting credit card default

I have this code for predicting credit card default and it works perfectly, but I am checking here to see if anybody could make it more efficient or compact. It is pretty long though, but please bear ...
5
votes
1answer
34 views

Codewars: N smallest elements in original order

I am consistently timing out on the mentioned kata: Task You will be given an array of random integers and a number n. You have to extract n smallest integers out of it preserving the original ...
-1
votes
0answers
54 views

Hackerrank Anansi's Ponzi scheme [on hold]

Problem Description Anansi wants to never work in his life again! So, being the trickster that he is, he decides to invest n dollars to start a Ponzi Scheme club. In this club, there are ...
2
votes
2answers
49 views

Python program to find the topic with the most meeting time dedicated to it

I must create a program for information regarding schedules and topics of meetings at work. The data relating to the meetings are stored in an "M" matrix with 5 columns, in which the generic row [g, m,...
-3
votes
1answer
13 views

ID Confirming system, glitches [on hold]

Hey I'm doing ID confirm system, which is equal to login system. And one bug, that I have discovered, is that this system is based on TXT file, so when the code is checking the user id, which he typed,...
1
vote
2answers
39 views

Find maximum length of array where every entries are the same

Is the complexity of this code \$O(n^3)$? How can I improve the efficiency and reduce the complexity? ...
2
votes
1answer
27 views

CSV/JSON converter

This is my first Python script and I would like to hear the opinion of more experienced users, so I can do it right from the beginning instead of trying to correct my mistakes after months (years?) of ...
1
vote
2answers
47 views
1
vote
1answer
21 views

Inverse mapping with bilinear interpolation on an image

The following is my solution for an inverse mapping with bilinear interpolation on an image. The original image is img and ...
-1
votes
0answers
22 views

Enigma machine implementation (Python 3) [on hold]

So guys, maybe this kind of question has been asked many times before, but I finally tried to implement this Enigma machine. I have done it half the way: The algorithm is revertible. However, it ...
2
votes
0answers
18 views

setting up mock and fixtures for for multiple pytest unit tests

I've been implementing a MySQL client with the later purpose of automating monthly reports. At the moment, I've got two distinct use cases: Executing a query and printing the results in files. The ...
1
vote
2answers
60 views

Find an order with the minimum total price

We want to create an application for the analysis of the order history at an online store. Each order is made by a customer and concerns the purchase of one or more items. Orders are stored in ...
-1
votes
0answers
19 views

Python Test Quiz with Numeric Answers ranging 0 to 5 - Need help finishing the code [on hold]

The user must give a grade ranging from 0 to 5 for each question. Then I need to sum the grades of each block (A, B, C, D, E, F, G, H and I) and print each block and the highest block score. ...
2
votes
1answer
50 views

Finding recessions in US GDP data using pandas

For an assignment, I am identifying the first quarter of the 2008 recession in the United States. The Excel data I'm using can be downloaded here: gdplev.xls. How can I improve this pandas code to ...
2
votes
1answer
23 views

GIF/PPM to greyscale converter

This is my take on an image → greyscale converter. ...
4
votes
2answers
42 views

Parsing Bitcoin binary data file with Python

The script parses Bitcoin database (blkXXXXX.dat) files directly from raw binary to txt human readable view. And I think about how to encrease the speed of processing. Can anyone suggest how to ...
3
votes
0answers
36 views

Socket chat room in Python

This is a Python chat room that I've been working on and it enables to you to chat to other people on the same network through Python. Server.py: ...
1
vote
0answers
23 views

Python script to add unittest decorators to source code files

This is a simple Python script to add @unittest.skipUnless() decorators in a specified format above every function starting with ...
1
vote
1answer
26 views

Creating folders even if already exist or removing removing their content

I have a project where, every time I run it, I have to: test if some folders exist, and create them if they don't exists. remove their content if the folders already exist. This is the code that I ...
3
votes
0answers
45 views

Metaclass to run a __first__ method for the first instantiation of a class

I had an idea for a __first__ special method for a class. It would be run after __new__ and before ...
5
votes
1answer
57 views

Linear regression on points specified by the user in a GUI

Here's my take on the Linear Regression exercise from John Zelle's Python book. Open a window, let the user click on as many points as they want. Upon pressing the "Done" button the regression line ...
-2
votes
0answers
35 views

Is there a way to compress this? [on hold]

This code seems very large and clunky, but I don't know any way of compressing it and making it smaller. Does anyone have any solutions? ...
1
vote
0answers
12 views

how to take the linspace of values between 2 columns in pandas [on hold]

I am trying to take the linspace of between 2 columns of a dataset. Heres an example. a b C D 0 3 13 3 13 1 4 14 4 14 2 5 15 5 15 ...
2
votes
1answer
44 views

Fast Factorisation (Python Implementation)

An algorithm for finding prime factors of a number given a list of all primes up to the square root of the number. It's worst case time complexity is \$O(n^{1/2})\$, the best case would be \$O(\log(n))...
0
votes
1answer
51 views

Fast Prime Sieve (Python Implementation)

A modified version of the prime sieve. I actually doubt it could be implemented any faster, but I might be wrong: ...
1
vote
0answers
16 views

Python Text Analysis with TextBlob — Reading lines from The Office TV Show

I have a Jupyter notebook that allows a user to type in a phrase and the program will 'guess' which Office character it resembles. Here is a link to the github repo I have the following littered ...
1
vote
0answers
45 views

Optimize Application of Python Gensim Search Functions

I have a DataFrame that has a text column. I am splitting the DataFrame into two parts based on the value in another column. One of those parts is indexed into a gensim similarity model. The other ...
-2
votes
0answers
22 views

Generalized Hailstone that converges with the sequences [on hold]

Can someone please help me solve this problem in python? Thank you in advance! ...
3
votes
0answers
25 views

Export EXIF data from thousands of images to CSV

I have written a script that retrieves specific fields of Exif data from thousands of images in a directory (including subdirectories) and saves the info to a csv file: ...
0
votes
0answers
15 views

A simple toy ResNet model and its implementation

I want to understand how resnet works also called us residual networks and I understand it better when I code one myself. I tried to find a simple implementation of resnet in the web but most I found ...
-3
votes
0answers
17 views
10
votes
3answers
3k views

Goldbach's conjecture algorithm

I did a Goldbach's Conjecture exercise and got it to work. It's pretty slow though and I was wondering how I could optimize it. ...
1
vote
0answers
24 views

See if a specific resource exists in a Kubernetes namespace

I want to have a function that checks to see if a certain resource (deployment, job, cronjob etc) exist in a namespace. Using the Kubernetes Python client, I can create a boolean function (using ...
4
votes
1answer
41 views

Python Pygame treasure hunt game

This is a python game that I am working on. It is a grid based treasure hunt game in which you collect coins from specific tiles (some tiles ask you questions in which you need to answer correctly in ...