Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

3
votes
2answers
76 views

'Broken Record' Coding Challenge

I was asked to complete a coding challenge for an interview. The challenge being to write a test function to check whether or not a string was a broken record. A <...
2
votes
2answers
53 views

SPOJ ADDREV challenge - Adding reversed numbers

I'm a beginner Python (2.7) programmer, and I've just started solving basic problems on SPOJ. I correctly solved the ADDREV problem (http://www.spoj.com/problems/ADDREV/), however my code takes 0.06s ...
2
votes
0answers
32 views

A class to create and modify SQLite3 databases with a terminal

I would like feedback on the class I've written. The purpose is to dynamically create and interact with SQLite3 databases, accepting lists of complete or incomplete statements. ...
6
votes
1answer
33 views

Python App that parses file for lines that match a format

I recently wrote some code that was dinged on not having well defined tests and poor modularity. Was hoping someone could review my code and give me pointers on how to create more well-defined tests (...
4
votes
2answers
53 views

Implementation of a queue for digicode-like system

What it is about I created an application where you need to push invisible buttons in a certain order to unlock the advanced mode. To handle this, I wanted to use a queue (FIFO) of my own, adapted to ...
20
votes
6answers
2k views

Check if a Sudoku board is filled out correctly

The code below takes a filled out Sudoku board of size NxN, with sub-blocks of nxn, and checks if the solution is correct. main_function takes a board as input. ...
3
votes
2answers
73 views

Calculate the path sum of a binary tree

I want to calculate all sum of all possible paths from root to leaf. Each node has value of an integer number (decimal). In the following example: ...
9
votes
2answers
296 views

Predict the next number in any sequence

Yesterday, I came up with a simple method to predict the next value in a sequence. The method works like this: Start with a sequence, say 1,4,9,16,25,36, call it ...
6
votes
2answers
742 views

Algorithm to say if win or lose using player's rating and randomness

I wrote a small simulator to understand the Elo rating system. I can create players, matches and tournaments, and I want to be able to predict the match ending depending on the rating of each player ...
6
votes
1answer
139 views

Decimal to binary algorithm

Is there a better way to code this specific algorithm using successively division through 2 which converts decimal numbers into binary numbers without calling a built-in function? ...
3
votes
1answer
40 views

Logical functions and truth tables

This program goes through 7 common logical functions (AND, OR, NOT, ...
13
votes
1answer
78 views

#TODO Remove duplication in XML parsing

I have to modify the number of points in this XML in order to test the performance of another program of mine. Here is an example of the XML I have to modify. performance.xml: ...
7
votes
1answer
99 views

Lightweight LED library

One of the projects that have been on my to-do list since years involves controlling a number of Inter-Integrated Circuit (\$I^2C\$) peripherals. Lately I've been turning everything into it's own ...
3
votes
1answer
52 views

Count digits in a given number using recursion

Here is my code that finds the number of digits in a given integer (either positive or negative). The code works and results in expected output. ...
3
votes
1answer
24 views

Basic call-and-response Slack bot

I'd love thoughts on how to make this more elegant. I'm planning to add some additional functionality, but basically this is just my first pass at creating a pythonic Slack bot from scratch. You ...
1
vote
0answers
38 views

Properties Manager

I'm trying to do a property manager that loads a yaml file and stores all the properties in a db. I'm not sure if this would be the right approach. Any suggestions? ...
7
votes
1answer
52 views

A CNN in Python WITHOUT frameworks

Here's some code that I've written for implementing a Convolutional Neural Network for recognising handwritten digits from the MNIST dataset over the last two days (after a lot of research into ...
-1
votes
3answers
98 views

Shortest prime number generator we could come up with?

I worked with a friend on the following prime number generator. Our goal was to make it as short and as fast as possible. This is what we came up with: ...
1
vote
1answer
51 views

Permutations part two

This is a follow up from this question. The goal is to make some function that can return the number of possible permutations with repetitions. As Gareth pointed out there is a nice formula for this ...
0
votes
1answer
34 views

Calculating and printing a credit card balance

I am working on a problem that simply calculates and prints the credit card balance. I hope this code can be improved/optimized a lot. I am from a Java background. If it was Java code, I would have ...
2
votes
0answers
68 views

Display a simulation using Tkinter

I wrote a module to simulate physics of 2D elastic balls and the community helped me to improve it on this post. Now I implemented a GUI using Tkinter to display the simulation in a window. I'm a ...
9
votes
1answer
238 views

A prefix notation calculator that asks about everything step by step

I made a prefix notation calculator. Prefix notation, aka Polish notation, is a form of notation for logic, arithmetic and algebra, like infix and postfix (reverse Polish) notation. The expression '+...
7
votes
2answers
84 views

Sum of prime factors of binomial coefficients over 9000!\${}\$

The problem I have lately been working Project Euler: 231: The prime factorisation of binomial coefficients The binomial coefficient \$ ^{10}C_3 = 120 \$. \$ 120 = 2^3 × 3 × 5 = 2 × 2 ...
3
votes
1answer
83 views

Minimum window substring

The minimum window substring problem from leetcode.com asks: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity \$O(n)\$. ...
4
votes
3answers
54 views

Codewars “Find the Parity Outlier” code

I completed this Codewars exercise. Here are the instructions: You are given an array (which will have a length of at least 3, but could be very large) containing integers. The integers in the ...
3
votes
1answer
59 views

Converting embedded JSON into flat table

I am new Python user, who decided to use Python to create simple application that allows for converting json files into flat table and saving the output in cvs format. I was wondering if you could ...
2
votes
2answers
71 views

Circular primes below 10^1025

The problem Project Euler: 35 is stated in the following way Circular primes Problem 35 The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and ...
4
votes
1answer
89 views

Migrate files from MySQL BLOBs to PostgreSQL largeobjects

As title says, this piece of code migrates files (binary and metadata) from a database to another one with different structure. Currently my problem is that when I have to deal with a big database (...
-1
votes
1answer
55 views

Classes (and maybe subclasses) for characters in a Python game

I am practicing classes and subclasses in Python. I'm not sure whether it might be useful to add a subclass to the following code, instead of just adding methods to the class. ...
5
votes
2answers
111 views

The right way to hang a man: final part

The problem: Making a simple hangman game. This is a continuation of the following question: The right way to hang a man. There I just tried to make the ascii-gallow. Now I have tried to write the ...
25
votes
1answer
3k views

The right way to hang a man

Problem: I have seen a few questions around hangman. Usually this is done in a very hackish way, which usually can not be generalized any further. My thought or question is about the creation of the ...
4
votes
1answer
100 views

Finding the similarity between the two movies using Pearson correlation coefficient

I am trying to find the similarity between the two movies using Pearson correlation coefficient. The programs is working well for small inputs but for large inputs (like 100000 lines) it takes forever....
6
votes
1answer
39 views

Quoted string parser

I have written a string parser that is designed to split a string by spaces, excluding spaces wrapped in strings. Here is some example inputs and outputs: ...
1
vote
1answer
30 views

Foldify - A Python Folder Tree Manager Tool

The goal was to create a tool to help manage folders structures, and allow me to create templates of this folders and store them as a JSON template. The following functionalities have been implemented:...
1
vote
0answers
31 views

generating nested lists in python2.7 [closed]

I'm building a "2048" game a la http://2048game.com/ So far, I'm just putting the main class together and hammering out a useful __str__(): function: ...
1
vote
0answers
22 views

Creating multiple objects using two forms

I would appreciate if you check my code and tell me what should I change. The code finally works but it could be much clear in my opinion. This is all about creating an ...
1
vote
1answer
67 views

Parsing Python arguments

I'm trying to cover the following 4 scenarios: No parameters DB param DB param and 1 option No DB param and 1 option So far I have the program working for all scenarios. However, I'm not happy ...
6
votes
2answers
98 views

Dice roller in Python

I'm trying to get better in Python and decided to rewrite my dice roller in Perl into Python. ...
46
votes
3answers
7k views

Monopoly simulator

I was advised by a Reddit user to get my code reviewed on this site. The complete code is on GitHub. ...
5
votes
2answers
99 views

Writing a hiveserver2 query result to CSV with Python using pyhs2

I am trying to create a small application that will help me extract data from Hadoop via hiveserver2 by simply writing it to CSV. At the moment, it takes about 40 seconds to pull 10,000 records from a ...
1
vote
1answer
134 views

A simple Hangman game in Python

I'm a noobie in programming so I've made a simple hangman game in python and I'd like someone to tell me how I could improve the code. edit:How could I do it using classes? ...
3
votes
1answer
62 views

Beating a dead horse: Project Euler 4

The task A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the ...
1
vote
2answers
61 views

Counting pairs of integers which have a predefined difference

I'm doing this HackerRank problem: Given \$N\$ integers, count the number of pairs of integers whose difference is \$K\$. So far, I've ended up with this code: ...
0
votes
1answer
82 views

Calculate the arclength

I am trying to estimate a good approximation for the arclength of the curve \$ y = \sqrt{1-x^2}\$ for \$x \in [0, 1]\$. I did this using a Bezièr curve, and made it so that the area under the two ...
1
vote
1answer
56 views

Grouping the results in an array having same name

results is a list of dict having panel name and work type and price to do that work on that panel. There can be two dicts for same name and work type where one of ...
1
vote
0answers
29 views

Scrape google apps page and store application details in database

Below is a python script which scrapes specific google apps url for example https://play.google.com/store/apps/details?id=com.mojang.minecraftpe and save the ...
1
vote
1answer
44 views

Python file reader/writer, with processing pipeline and context manager

The following code does three things: The filename is determined by the RawData class The reader and writer send data through a processing pipeline (Hopefully) makes changes and extensions easy ...
4
votes
1answer
82 views

Checking to see if array can be sorted using only one operation

I'm doing this HackerRank problem, which asks whether an array of up to 100000 integers can be sorted in ascending order by exactly one of the following: swapping two elements reversing a subarray ...
0
votes
0answers
39 views

Find matches between two tables after downsampling

I am trying to find matches between two tables by downsampling so that they fit into memory and we are able to find a good number of matches. For one of the tables, I have created an inverted index on ...
6
votes
1answer
110 views

Palindromes that are sum of consecutive squares

I have been working on a Project Euler: 125, which took me ages to solve. The problem and source are cited below The palindromic number 595 is interesting because it can be written as the sum ...