Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
4
votes
1answer
35 views
Find minimum in rotated sorted array
The given code find the minimum element in a sorted array rotated by some fixed distance.
Eg: [1, 2, 3, 4, 5, 6, 7] -> [3, 4, 5, 6, 7, 1, 2]
The elements in the ...
1
vote
0answers
13 views
Python GUI for cropping and saving images quickly
I wrote a simple GUI applications to help me select 'positive' regions of a bunch of photos for the purpose of training an object detectir using OpenCV Haar Cascades.
For training purposes, you need ...
-4
votes
0answers
26 views
Return lexicographically earliest string [on hold]
Write a function called answer(chunk, word) that returns the shortest, lexicographically earliest string that can be formed by removing occurrences of word from ...
2
votes
1answer
26 views
Plugin Pattern for Generic Python Application
Summary
I am experimenting with a plugin pattern for a generic Python application (not necessarily web, desktop, or console) which would allow packages dropped into a plugin folder to be used ...
1
vote
2answers
138 views
-3
votes
0answers
18 views
10
votes
6answers
1k views
2048 merge function
From: Principles of Computing Part 1 Course on Coursera
I got -2 pts on my OWLTEST which uses Pylint for style guide. The error states:
Too many branches (17/12)
function "merge", line 7
...
6
votes
1answer
36 views
Recursive search for combinations of words that have a specified MD5 hash
This code solves a challenge problem that a local company is hosting to attract/screen applicants. The link to the challenge is here.
In brief, we are given a wordlist containing approximately ...
2
votes
0answers
35 views
Subset sum whose set contains only positive integers
I was trying to write a dynamic programming algorithm using a bottom up approach that solves the subset sum problem's version where the solution can be either an empty set and the initial set can only ...
4
votes
4answers
57 views
Recursive binary search in Python
I have implemented a recursive binary search in Python and tried to implement some verification to my code. Other than that, is there any optimization I am missing?
...
3
votes
4answers
68 views
Efficiently concatenate substrings of long list of strings
I am having performance problems with the following python function:
...
4
votes
2answers
37 views
Conversion of an array of integers to string
In order to save memory space. Strings inside an embedded device are stored in a particular way. Each 32-bit location holds up to 4 chars instead of only 1 char in the usual case.
I wrote a function ...
4
votes
2answers
272 views
12
votes
6answers
1k views
Project Euler #1: Multiples of 3 and 5
Challenge Description:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples ...
5
votes
1answer
46 views
“Lights Off” puzzle in tkinter
I'm a newbie in Tkinter and I've managed to make the "Lights Off" puzzle using Tkinter with Python 3.
The game starts by presenting 9 buttons arranged in a 3x3 matrix. The text of the button will be ...
11
votes
1answer
93 views
3D Tic Tac Toe/Connect Four game with AI
I came up with this during English lessons many years ago to kill some time, and just decided to try code it. It's basically a 3D version of Connect Four/Noughts and Crosses/Tic Tac Toe, but the grid ...
2
votes
1answer
37 views
Tic-Tac-Toe class written in Python
How well is this Tic Tac Toe code written? Where may I improve it? This is meant to be a platform for a machine learning algorithm.
The code is written so any player may play first. Once a player ...
-5
votes
0answers
25 views
Ten Green Bottles please give me a hand i cant work it out [on hold]
This open a file given as filename for reading returns the String containing the contents of the file
...
12
votes
5answers
968 views
Finding the 10001st prime
I'm solving Project Euler problem 7, which says:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?
Here's the ...
5
votes
2answers
35 views
Regex for finding After Effects files in scene code format
I haven't used regex a lot and I needed to set up a script that can gather a list of file paths that should adhere to a strict formatting convention, so I thought that sounded like a good opportunity ...
3
votes
1answer
24 views
-1
votes
0answers
23 views
Django application - code improvements and best practices [on hold]
I have just finished a Django application, and I would like to get from you some code reviews related to my code.
Application flow:
Basically, my application is accessing a specific URL (always the ...
3
votes
2answers
44 views
Analyze very large sets of engineering data from Excel files
I am an electrical power engineer with some programing skills. My boss asked me to make a program which could analyze very large data, make some calculations and give the result.
The task lookes like ...
1
vote
1answer
40 views
Calculate trapped “rain water” in structure [on hold]
Supposed my input is [1, 4, 2, 5, 1, 2, 3] . Then we can create a
structure like this:
...
8
votes
5answers
647 views
Reversing a number
I was working through a programming challenge I found on Reddit and it seemed easy enough:
Find all numbers less than \$10^n\$ where the number and its reverse (the reverse of \$123\$ is \$321\$) ...
3
votes
1answer
51 views
A tool to help you memorize text
I wrote a snippet of code to help me memorize text out of files and was hoping to get some feedback on the code, since Python isn't my strongest language.
You can see the code on GitHub, but I've ...
4
votes
1answer
25 views
Webscraping Bing wallpapers
I wanted to scrape all the wallpapers from the Bing wallpaper gallery. This was for personal use and to learn about webscraping. The gallery progressively gets images using javascript as the user ...
7
votes
3answers
137 views
Finding the shortest excerpt that contains all search terms
Write a function called answer(document, searchTerms) which
returns the shortest snippet of the document, containing all of the
given search terms. The ...
4
votes
3answers
47 views
Converting Pandoc Markdown images from captioned to inline
After writing a rather long document in Markdown and using pandoc to convert it to a PDF, I found, to my dismay, that many of the images were out of place, and that they all had their alternate text ...
8
votes
4answers
571 views
Project Euler #2 in Python
Here is my Python code for Project Euler #2:
Each new term in the Fibonacci sequence is generated by adding the
previous two terms. By starting with 1 and 2, the first 10 terms will
be:
...
5
votes
2answers
44 views
Finding the rod pieces in the rod cut issue
I have been reading the chapter 15 of "Introduction to Algorithms" (3rd edition) by Cormen, etc. The chapter 15 is about dynamic programming, and the first example they show us is the "rod cut ...
8
votes
2answers
98 views
Summation of primes for large inputs
I'm doing a problem from Project Euler to find the sum of all primes under two million.
My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it ...
6
votes
2answers
45 views
Encrypter - Double Vigenere Cipher in Python
I wrote this encrypter based on the idea of a Vigenere cipher, but instead of using only one key, it "makes" another key from the existing key. The length of the second key also depends on the ...
9
votes
5answers
377 views
Birthday validity-checking
I have written code to check any birthday input's validity. As I am new in programming, and after going through several debugging steps, the code became very ugly.
...
3
votes
1answer
74 views
Function to rebalance portfolio
I wrote a small code in Python to conduct a backtest. My 'rebalance' function is very slow and I would like to improve it. I need to profile it but I would welcome any opinion on how to refactor my ...
11
votes
1answer
70 views
Racetrack plotter
My Racetrack is just that. A Racetrack. You can't race it (yet) because I had trouble with collision detection, but I wanted to share it anyway.
It creates a base polygon by using ...
6
votes
4answers
67 views
Join strings with different delimiters and some possibly empty strings
I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
1
vote
0answers
13 views
Join strings with different delimiters from possibly empty strings [duplicate]
I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
9
votes
5answers
1k views
6
votes
1answer
51 views
Hangman with ASCII
I have just made a game called Hangman. I have added some stuff which people don't normally use, like cheat-code/s, time.sleep().
How can I improve this, in both ...
7
votes
1answer
74 views
Python snake game
If anyone has the patience to take a look at my first python snake game, I'd be very grateful for any feedback. I am fairly new to programming and Python, but am looking to improve so any constructive ...
4
votes
2answers
60 views
Get all followers and friends of a Twitter user
I'm trying to find my bug or any potential bottleneck that cause my program to be really slow. The script is to get all the followers and friends and save that in MongoDB.
...
4
votes
2answers
59 views
Dataset and frequency list generation by looping over files
I have been told that it would be wise to split up my code into semantically useful blocks. I tried the following but I need feedback.
What I already did:
As you can see I create two .csv files, so ...
8
votes
2answers
89 views
'Mini Twitter' in Python 3
I've written a 'Mini Twitter' (that's what I've called it) in Python. It includes a text-based login screen and user panel where you can create Tweets, and change your username and password.
Users' ...
3
votes
1answer
35 views
Process PowerPoint XML
I run a tiny open source project to help create speech aids for disabled people (the github is here).
One of the things that is useful is for people to design speech setups in Powerpoint, and then ...
3
votes
0answers
31 views
Item purchasing using urllib
I have this function that gets an item passed from another function, together with the subtotal and the fee of the item. The function has to act as fast as possible, as other people also want the ...
10
votes
5answers
767 views
Generating a password to save to a .txt file
Here is my basic password generator which saves your password to a .txt file which you can choose the name of etc.
...
4
votes
2answers
43 views
Test if a network is online by using urllib2
My concerns:
Is the code pythonic
Is the code practical
I tend on expanding the usefulness of this script, if you don't think it's stupid idea. One thing I will implement is command-line arguments ...
2
votes
1answer
57 views
Bot that selects web reviews based on spreadsheet entries
In my program, I prompt the user to enter a range of cities (in a spreadsheet), and then a range of review scores, and then make some decisions based on what the user has entered. Since the handling ...
6
votes
1answer
70 views
Avoiding code repetition while handling exceptions
For my application, I need to use two slightly different algorithms for persisting an entity:
...