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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

1
vote
1answer
19 views

k-armed bandit problem in Python

I implemented k-armed bandit problem in C#, MATLAB and Python. C# and Matlab code run fairly fast (With same settings of T = 2000 and nRun = 1000 the elapsed time is about 6sec). However, the Python ...
0
votes
0answers
23 views

Finding center of graph/tree

Given graph/network of nodes without any loops/circuits. I'm trying to find the center: the node from which i can reach all other nodes the fastest. Imagine if i want to spread the word about ...
-2
votes
0answers
9 views

WEB Crawler help needed [on hold]

If I have a form built on my website. How can I get that form 1 to plugin results into another websites form 2 and extract information to display on my website? For example, if I wanted to create a ...
3
votes
2answers
31 views

Python 2.7 Powerball Game

This game allows one to either pick their own lottery numbers or have them generated and checks them with the most recent numbers, jackpot, and multiplier. I use concepts such as ...
1
vote
1answer
24 views

Extended matrix generation

I am extending a matrix with some calculated values. This code runs very slowly. Is there a way to vectorize this with slice and ...
2
votes
0answers
20 views

Set positions in a list, keeping tied places then incrementing back to the positions

I have a list of objects which have points and I'm looping through this list to assign the object's position in the list. If the points are tied between multiple objects they share the same position ...
6
votes
2answers
203 views

Find files by pattern and copy to target location

This is my solution to the Chapter 9 exercise in Automate the Boring Stuff: Selective Copy Write a program that walks through a folder tree and searches for files with a certain file extension ...
7
votes
2answers
1k views

CodeFights: Frisbees

Description You and your friends are seizing another summer day, passing around the frisbee in the park. You have the most fun when the game is fair, so as much as possible, you would all like to ...
2
votes
0answers
23 views

Crypt-arithmetic solver (Brute force) in Python

I'm working on a crypt-arithmetic solver to add two or more numbers. I've used brute-force to find all the permutations. I'm looking forward to improve this algorithm. Kindly review for all the ...
2
votes
0answers
21 views

Pytest fixture for testing a vertex-parsing function

I have just started using pytest and I am still getting used to how they do things. It seems like fixtures are at the core of the library, and that they can be used for making small pieces of dummy ...
3
votes
2answers
87 views

Find smallest sum of squares to make a number

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...
0
votes
0answers
17 views

Basic dictionary script [on hold]

Well i have this code i wrote that prints the inventory ...
6
votes
1answer
52 views

Simple CLI Python Hangman game

Preamble: I am very new to Python, and outside of Googling functions and a former work colleague telling me why I'm wrong, I have no formal training and haven't taken any "Learn Python" courses. I ...
-3
votes
0answers
24 views
7
votes
2answers
79 views

Determining optimal weight lifting bar configuration

This program is meant to take two weights and return the best way to load a barbell for two people using different weights, so you don't have to keep changing out super heavy weights. I also made ...
7
votes
3answers
58 views

Getting a key's value in a nested dictionary

I just found a now deleted question on Stack Overflow and solved the problem. The OP was asking for a way to get all the values contained by all 'PLU' keys. I solved it this way but because I am a ...
7
votes
4answers
336 views

Median Calculation of List of Integers without using heap

References Using those references: rolling median implementations benchmark FAST RUNNING MEDIAN USING AN INDEXABLE SKIPLIST Calculate the median of a billion numbers Find running median from a ...
5
votes
3answers
135 views

Disjoint cycles of a permutation

Given an element of the permutation group, expressed in Cauchy notation, it is often useful to have it expressed in disjoint cycles (for example to apply the permutation to the keys of a dictionary). ...
1
vote
0answers
29 views

Python GUI Calculator - Passing Variables Between Classes [on hold]

I've recently come across this code that another user submitted for their python calculator using tkinter and have a few questions regarding it if anyone can help. I fully understand how they made ...
3
votes
3answers
82 views

Find the year when the user will turn 100

I moved to Python today after doing a little of c++. The following code works as intended, but I want to know if I should add the if __name__ == "__main__" ...
3
votes
0answers
15 views

PyQt layout wrapper with indents

As I'm sure a lot of you are aware, the layout files generated for Qt look quite horrible. Maya had a wrapper that let you indent each widget when building manually, so I decided to have a try with ...
0
votes
1answer
33 views

Binary search tree traversal and depth first search in Python

I am learning about the tree traversal, and I would like to ask for feedback. Using recursion, write a function that takes in a binary search tree and number of outputs a list of values ordered by ...
2
votes
0answers
28 views

Madlib CLI program, replaces string in text file

Mad Libs program that reads in text files and lets the user add their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file. ...
2
votes
1answer
53 views

Image processing using Python OOP library

I am trying to learn OOP by refactoring my existing code (functions only). This example works but I am not sure whether it is pythonic and good practice. I have a shared library which consist of ...
-2
votes
1answer
84 views

Project Euler Problem 1 with Python 3 ideal solution

I have been playing around in hacker rank with Python these days, and now pulling my hair out on this question to solve the Euler's problem in the least time required. If we list all the natural ...
6
votes
0answers
53 views

Using decorated methods in a subclass of deque to dump its state to a JSON file

I am sub-classing an object in python and I need to overload a bunch of the methods with very similar logic, essentially a call to super() and then some additional operations. I want to avoid ...
-2
votes
0answers
25 views

Python ABS Chapter 8 - Allow users to change words in a text via Input [on hold]

So the assignment is: Create a Mad Libs program that reads in text files and lets the user add their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file. For ...
5
votes
2answers
340 views

Check for pixel spacing between two folder images

Im trying to match the pixel spacing between two folders, here matches has 994 keys and it shows that i may take more than a day to compute this. Is there any way i can speed up this operation. the ...
2
votes
2answers
53 views

Parsing date strings, inferring the year such that the date is not in the future

I got this program that I am working on and in it, I got a section that has a try statement and two error except statements. ...
0
votes
1answer
30 views

Create new columns using groupby in pandas [on hold]

I'm running into a large bottleneck in my program that takes hours to perform. I have a Dataframe that is very large. I need to take the columns of the Dataframe and create new columns within same ...
3
votes
2answers
48 views

Using Python to create a JSON file of recipes from MySQL

I needed to create a JSON file from a couple of MySQL tables to migrate some recipes from wordpress. This was my first time writing a script in python and would like to get some feedback on what I ...
-4
votes
0answers
19 views

computer guessing game [closed]

The while loop in my code doesn't work! Does anyone get this? I am referring to the first loop, and any other errors. Here is the code: ...
2
votes
2answers
192 views

Credit card validity check [on hold]

I want to go more in depth, but this is the 'boilerplate'. Is there any way I can optimize this or use more idiomatic Python code? ...
2
votes
0answers
47 views

Numerical evaluation of line integral

I have written a function that evaluates a contour integral in Python (Poincaré - Hopf index for 2D vector fields). It works, however is really slow if the arg res=N...
0
votes
0answers
36 views

Greatest prime factor [closed]

Code: (edits are appreciated) ...
5
votes
1answer
35 views

Personal School Course Scheduler

A good friend of mine had the challenge of trying to build a schedule using all available times and classes through a spreadsheet... by hand. He asked me if I could build a program to generate valid ...
5
votes
2answers
91 views

Finite state automata

This is a non-deterministic finite state automata (NFA) meant to be used with a Regex engine. To show some example usage, suppose you wanted to construct an NFA for the regex ...
-2
votes
0answers
29 views

How would I print this together? [closed]

So I am new to Python, so if you could advise me to change my code to be better, please do so. Anyways, I cant figure out how to print the text and the variable together. I would like it to show the ...
1
vote
2answers
35 views

BST implementation for insert (put) and contain (search) in Python

I was asked about this question by my friend, so I decided to implement it recursively. I would like to get some code review. ...
5
votes
2answers
66 views

2048 style game

I have made a replica of the game 2048. It works exactly how the game should work. However I was just looking to know where I could've possibly cleaned up my code or make it more efficient. ...
4
votes
2answers
56 views

TicTacToe game in Python 3

I wrote this program in Python 3.I would like to know if there is some more functionality that could be added/removed/is missing.Any comments would be helpful! ...
3
votes
3answers
274 views

“Longest Substring Without Repeating Characters” in Python

I was trying to solve this problem from Leetcode: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", ...
-5
votes
1answer
34 views
0
votes
1answer
48 views

Blackjack strategy simulation

I'm very new to python (been coding for about two days) and have created a programme that simulates blackjack games so that I can work out optimal strategy over many iterations. The problem is that ...
3
votes
2answers
32 views

Utility functions for processing tweets or texts

I have 4 functions that process texts or tweepy.models.Status object (this object stores text information, author information, retweets & likes information of a ...
-4
votes
0answers
15 views

Schedule for 10 people for Sundays for 3 months [closed]

I have to prepare a Scheduler for N number of people to be sent to Y number of places on Sunday only where no two person can be at a same place. They have provided with their list of holidays before ...
3
votes
3answers
126 views
+100

Express a number as a sum of powers of 2

This is my function: ...
0
votes
0answers
30 views

Python scraper for a legal database

I wrote a scraper to get all the details of cases in the Indian supreme court from this link here. The current code is expected to get me the following details - the Title of the case, the number of ...
8
votes
2answers
80 views

Python 3 two-sum performance

I just submitted a Python solution to the 'Two Sum' problem on LeetCode. The Problem Given an array of integers, return indices of the two numbers such that they add up to a specific target. ...