Stack Exchange Network

Stack Exchange network consists of 175 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.

2
votes
0answers
32 views

A recursive Boggle solver

`Boggle is a word game in which letters are randomly placed in a 4x4 grid e.g: A D Q P N L E M O S R T V K J H Words can be started from any letter and are ...
2
votes
0answers
30 views

Python adding partialmethods to a class at compile time

I am writing a class for delayed operations on variables which are resolved at a later time. I am using pythons operator overloading but my class definition seems very boilerplatey. Is there a more ...
3
votes
2answers
224 views

Prime sieve in Python

I was trying to write Sieve for the first time and I come up with this code ...
3
votes
0answers
29 views

Deduping files using hardlinks

I'm trying to organize my gallery, and I have certain folders rife with copies. My daily work is mostly javascript and php, being your generic web developer. However I took this as an opportunity to ...
8
votes
2answers
636 views

Primes and SemiPrimes in Binary

I'm in the midst of re-learning python. My current effort is an implementation around prime factorization. I am attempting to reproduce something similar to the table found here (in binary): https://...
5
votes
0answers
30 views

Tensorflow loop to analyze gradients derived from MRI and PET images

The code shown below takes the partial derivative of each pixel of the output fused image of a neural network with respect to input image of the neural network using tensorflow's ...
-4
votes
0answers
33 views

How do I calculate the average grade from .txt file in Python? [on hold]

I am struggeling with a Python assignment. From a txt.file the average grade of each mentor needs to be calculated. The data in the txt.file looks like this: ...
3
votes
1answer
35 views

Apply same format function to each python print() parameter

I have a python print statement and inside the string I wish to print are four digits. I would like to apply the same formatting function to each param. I am not ...
-2
votes
0answers
38 views

Looping through this list takes time [on hold]

Below is the function which takes in list containing 3million elements and then creates another dictionary out of it for further lookups. This is an extremely time consuming function which after ...
0
votes
0answers
26 views

Cleaning words from numpy arrays [on hold]

I'm a new joiner in a software engineering team and have been given this code for refactoring. This code feels very gluey and dependent to me but I can't decide how to make it independent. This is ...
6
votes
1answer
81 views

Python3 OOP Tic-Tac-Toe

I'm studying Object-oriented Programming and decided to apply some things doing an Object-oriented Tic-Tac-Toe. I wanted to know if you have some hints of what to improve and why! ...
10
votes
3answers
1k views

Find the common ancestor between two nodes of a tree

Here is my code in Python for to find a common ancestor between two nodes in a particular tree. This is a question from Cracking the Coding Interview that I decided to implement on my own. No one has ...
-2
votes
0answers
42 views

Optimizing the speed of the code using C++ instead of Python [on hold]

I wrote code in python and it's like this: ...
1
vote
1answer
44 views

Sign-up serialization in Python [on hold]

I built a small project using Django-Rest-Framework. Please comment on the best practice style for the code below, which will make it simpler. ...
6
votes
1answer
55 views

Password validator making zxcvbn easy to use with Django

This is a translatable password validator for django, based on zxcvbn-python and available with ...
2
votes
2answers
208 views

Regex version of strip() - Ch. 7 Automate the Boring Stuff

Here is a practice exercise — Regex version of strip() \$-\$ Write a function that takes a string and does the same thing as the ...
4
votes
2answers
324 views

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

Here is a practice exercise — Fantasy Game Inventory \$-\$ You are creating a fantasy video game. The data structure to model the player’s inventory will be a dictionary where the keys are string ...
17
votes
6answers
3k views

Explicit song lyrics checker

To stay in practice with my Python I've decided to write an explicit song checker. It checks each word in the song against an array of 14 explicit words contained in the text file. I've decided not to ...
0
votes
2answers
55 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
5
votes
2answers
73 views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...
6
votes
2answers
72 views

Positive cumulative sum of difference

I have a water reservoir with input and output rates. I want to determine when the input is exceeding the output by a certain constant. To accomplish this, I need to cumulatively sum all cases where ...
6
votes
2answers
96 views

Class to generate a pdf invoice

I am learning to work with OOP design patterns and so I challenged myself with the idea of creating a way to generate a pdf invoice based on some information entered. So, this is what I have done so ...
5
votes
0answers
58 views

Parsing Long Excel Report Files for Predefined Results

I work as an IT intern in a multinational and I was given a tedious task of combing through a 2500+ long multi-column excel report file in search of inactive servers. Here's a sample row from that ...
6
votes
1answer
45 views

Updating generated file

With this algorithm I update an automatically generated verilog-file. The update within this file is done by commenting the assigned wires to specific ports of module instances. Is there a better, ...
1
vote
2answers
40 views

Leetcode 15 - 3 sum

This is a Leetcode problem - Given an array nums of n integers, are there elements \$a, b, c\$ in ...
-4
votes
0answers
35 views

Simple Tic Tac Toe python finish [on hold]

I'm a beginner in programming and I'm trying to make a tic tac toe program, but I have no idea on how to finish it. I like it simple, but interactive. Any tips? ...
2
votes
1answer
26 views

Whiten black contours around a skewed image

I have this image: I want to whiten the black contours (borders) around it without affecting the image content. Here is the code I used: ...
3
votes
0answers
33 views

Strongly Connected component algorithm implementation(Python)

My goal is to implement Strongly Connected Components algorithm using python. I have splitted up my code on 3 parts: Data Load: ...
7
votes
2answers
437 views

Word-Ladder solver in Python 3

Follow-up to Python program to find a word ladder transforming "four" to "five" I'm trying to write a program to solve a word ladder puzzle to brush up on my Python. For those who ...
3
votes
0answers
26 views

(Leetcode) Snakes and Ladders

This is a Leetcode problem - On an \$N\$ x \$N\$ board, the numbers from 1 to N * N are ...
5
votes
1answer
77 views

Shortest pathway across a snakes and ladders board (Update)

Earlier I posted a fairly inefficient recursive solution to the problem of getting across a snakes and ladders board in the smallest number of moves. I have created a much faster solution to this ...
5
votes
2answers
897 views

Fastest path on a snakes and ladders board

I am not looking for a detailed review of this code as I am aware it is very inefficient. The main reason for posting this is to see if there is a better way to achieve my goal (I am certain there ...
14
votes
4answers
3k views

100-doors puzzle

Here is a very simple solution to the 100 doors challenge You are in a hotel with 100 doors. Initially every door is closed. On the first round, you change the state of every door (if it is open, ...
-2
votes
0answers
25 views

Loop on dataframe takes a lot of time [on hold]

The dataframe subset feature is being used in a for loop across the dataframe rows. The result seems accurate however, the time taken to complete the loop on 2000 odd rows is more than 4 minutes. Any ...
7
votes
1answer
1k views

Python program to find a word ladder transforming “four” to “five”

I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform "four" to "five", forming a new four-letter word at each step, replacing one letter ...
5
votes
1answer
71 views

Tower of Hanoi with helper function

Here is a fairly straightforward solution in Python to the Tower of Hanoi problem ...
4
votes
4answers
124 views

Find the nth term of a sequence that consists of Fibonacci and prime numbers interleaved

I have given a series problem 1,2,1,3,2,5,3,7,5.... in which the odd terms forms the Fibonacci series and even terms form the prime number series. I have to write a code in which I have to find the ...
-5
votes
0answers
64 views

Algorithm for Egyptian Fraction [closed]

An Egyptian fraction was written as a sum of unit fractions, meaning the numerator is always 1; further, no two denominators can be the same. As easy way to create an Egyptian fraction is to ...
2
votes
1answer
41 views

Select optimal piecewise regression fit

I'm making a program which fits a piecewise linear regression with up to 4-5 breakpoints in the data, and then deciding how many breakpoints is best to prevent over and underfitting. However, my code ...
1
vote
1answer
32 views

Django export to xls format

I'm working on a Django project and I'm wondering if there is any way to improve the process time to export my data to xls format. Actually, it takes between 43 seconds and 49 seconds to create the ...
-3
votes
0answers
25 views

How can the length of a string be O(log(n))? [closed]

I have just started learning about time complexities and am currently reading Logarithmic Complexity. Here's an example of a piece of code which is O(log(n)). ...
4
votes
1answer
53 views

Pick the best combination of n choose k models

Algorithm Let \$M_0\$ denote the null model which contains no predictors. This model simply predicts the sample mean of each observation. For \$k=1,2,\ldots,n\$: Fit all \$n \choose k\...
4
votes
3answers
383 views

Generate parentheses solution

I have coded a solution to build all valid permutations of parentheses. My code is below. I have a question on my code based on a comment by my PEP8 checker. It said that there was no need to ...
3
votes
1answer
47 views

Optimizing Luhn check digit algorithm

The internet as a whole and Code Review in special already provide a decent amount of implementations of the Luhn check digit algorithm. They often follow a relatively "naive" strategy, in that they ...
-3
votes
0answers
13 views

Can't Seem to find why post_list returns empty/None? [closed]

I am trying to click the Show 2141 Comments Button on https://www5.gogoanime.tv/category/one-piece this page using selenium and then scraping all the comments. The button is clicking correctly using ...
6
votes
1answer
45 views

Irreversibly hash email addresses while preserving format/entropy

I'm looking to irreversibly hash valid email addresses which have been parsed from mail log data as part of a machine learning project. I need to ensure that the processed data has been scrubbed of ...
11
votes
1answer
166 views

Simple log rotation script

I created a simple script that implements log rotation. It checks the log file size (say, out.log) if it exceeds 5MB limit. If it does then the script copies it to <...
0
votes
2answers
119 views

(Leetcode) Brick wall

I would like to know whether I could make my solution to this Leetcode challenge much faster. There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The ...
-4
votes
0answers
28 views

This code works well, but not so well when I compile it to an EXE: os.execl(sys.executable,*([sys.executable]+sys.argv))…? [closed]

This code is working well from console, how can I improve it to make it work when compiled ? I want my program to restart completely when it comes to the end. The code below works fine from the ...
5
votes
3answers
96 views

Python solution for the N-Queens challenge

Here is my coded solution for the N-queens challenge The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. The program outputs all ...