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.

3
votes
1answer
7 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
1answer
14 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 ...
0
votes
1answer
14 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 ...
1
vote
0answers
5 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
23 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 ...
1
vote
0answers
17 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
22 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 ...
1
vote
2answers
35 views

Python program to find the topic with the longest meeting 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
12 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
34 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? ...
1
vote
1answer
22 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
1answer
20 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
17 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
1answer
49 views

Code and lists on Python

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 an "OR" ...
-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
32 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
32 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
39 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
11 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
50 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
24 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
14 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
23 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 ...
1
vote
1answer
20 views

Multiple database connections class

This is my database connection class in order to handle multiple connections with the use of context managers. Brief explanation: The __init__ method reads ...
2
votes
1answer
24 views

RESTful API echo server using Python bottles

I just wrote an echo server that responds to curl requests with the method used and the data sent. Sticking to GET and POST for now, but I would like to know if there's something I can do to improve ...
1
vote
1answer
35 views

Leetcode 3Sum problem using hashmap in Python

For practice, I solved Leetcode 15. 3Sum question: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives ...
-1
votes
0answers
15 views

When scraping webpage XPATH variable returns Unfinished Literal [on hold]

I am trying to scrape Amazon for ASIN Best Seller Rank and when I run the script in python it returns an unfinished literal error Everything works except for the Best Sellers Rank. I would really ...
6
votes
2answers
377 views

Python Making Brute Froce Crack Faster

I made an Brute Force Cracker with python, but its extremely slow. How can i make it faster? ...
2
votes
2answers
51 views

Chained Sort Python Implementation

So I've run into a few occasions where I'd want to sort a list according to a criteria, then for all loosely sorted sublists (a sequence of equal elements), I'd want to sort those sublists according ...
5
votes
2answers
408 views

Python update SQLite DB Values

At the moment I try to get used to SQLite and Python. I started with insert, select and so on. But now i want to get a bit further. Now I have a DB with 200 rows for testing and in want to update two ...
-5
votes
0answers
16 views

Losing the penny on the output [on hold]

I'm writing a Python script that will prompt the user for monetary value (such as 11.26). Then, calculate the number of dollars, quarters, dimes, nickels, and pennies. It should use the maximum ...
3
votes
1answer
56 views

Design of a Tic Tac Toe program in Python

Here is a program I wrote to reproduce the known win proportions for random Tic Tac Toe games (X always moving first). It takes about a minute to play the one million random games that will be played ...
2
votes
1answer
22 views

Refactoring coordinates for Minecraft Pi buildings written in Python

I'm fairly new to coding and I wrote this script in Python for a house with a roof in Minecraft Pi. I've found different ways to write the coordinates to make the code base shorter, but I'm wondering ...
4
votes
0answers
25 views

dynwg: A DynDNS watchdog for WireGuard via systemd-networkd

Preface I'm using WireGuard as a VPN solution to connect a remote client permanently to my home server. Unfortunately due to Consumer DSL-related IP address changes, the client loses the connection ...
1
vote
0answers
45 views
+50

Automating A Workflow Using Selenium - Best Way To Fetch Elements & Make Code More Generic

I'm a newbie to Selenium and I'm trying to get better at it by taking up interview assignments. This YouTube link describes the workflow that needs to be automated. The following points are worth ...