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

learn more… | top users | synonyms

3
votes
1answer
12 views

Making the Levenshtein distance code cleaner

I was writing an implementation of Levenshtein distance in Python and I found my code really ugly. Have you any idea how to make it more elegant? ...
1
vote
1answer
19 views

Summing all keys in the leaves of a tree

Input The input contains a single text line with eight positive integers A, B, M, L1, L2, L3, D, R separated by one or more spaces. These parameters regulate the ...
6
votes
1answer
24 views

Creating a family hierarchy

Requirement: For the input list of tuples to create single line output showing father of the family|spouse|child1,child2.... Input: ...
2
votes
0answers
8 views

Computing the in-degree of a tweet graph

This was my entry for a recent coding challenge for computing the in-degree of a tweet graph (the competition is over). The requirement was to compute the in-degree of a graph made from unique hash ...
1
vote
0answers
14 views

Scan over parameter iterator for model simulation in python

I'm writing a small python application that performs model simulation for many different parameters. The iterator of parameters isn't completely known ahead of time. Rather, the iterator needs to ...
-4
votes
0answers
7 views
4
votes
2answers
55 views

Number guessing game

i'm a beginner and this is the second program that i have written by myself from scratch, i wrote a basic snake game with PYgame but i didn't do it by myself, so anyway, what do you guys think of ...
2
votes
1answer
43 views

Recording all instances of a class - Python

In a programme that I am writing, I need to loop through all the instances of a class, the way I got around this was by appending every class to a list like below: ...
1
vote
0answers
23 views

Snell's law using Zoeppritz equation by matrices

I have created the following code to calculate Snell's law angles, based on Zoeppritz equations on complex plane. The code works, seems it is returning valid values, but after all the code just looks ...
1
vote
1answer
40 views

My implementation of counting sort [on hold]

I've made the following implementation of counting sort. I don't think that I understand the algorithm fully but this implementation seems to be working correctly. I've used the ...
2
votes
2answers
71 views

Segmenting a color wheel

I'm a fan of elegant ways to condense code. I find this ugly. Been staring at it for a while, can't think of a way to write this with less verbosity (ok, short of shorter var names but that's not what ...
3
votes
1answer
43 views

Sliding tiles solver in Python

I've implemented the sliding blocks puzzle in Python to solve it using different algorithms. I'd like to know if the class "Sliding_blocks" is nicely designed or if I am missing concepts of OOP. I ...
2
votes
2answers
72 views

Simulation of 2D elastic balls

Following this SO post and this Wikipedia article, I wrote a Python script to simulate physics of 2D elastic balls. I define the physical behaviour of each ball in the ...
3
votes
1answer
52 views

First time writing test case

I have a list of input, a greedy method and a dynamic programming method. I wrote a unittest script to test my two methods with input list but I don't know if I'm writing it right: ...
-4
votes
0answers
28 views

grading program in Python won't work [on hold]

This question about the Python coursera assignment 3.3 was already asked but that user had a different base to start that's why I'm asking again. Here is the assignment: Write a program to prompt ...
-3
votes
1answer
29 views

this procedure basically gets a sentence of the user and the splits it up into its position values and writes them to a file

this program does work entirely without any errors appearing however I would like to shorten it down to make it more reliable and neat ...
10
votes
2answers
90 views

Python Keylogger With Built In Security Measures

The program I have developed is currently used for detecting and recording keystrokes. I have added some built in security measures that can easily(somewhat) be modified to suit individual user needs! ...
3
votes
1answer
38 views

Python Find Tuple by Geographic Priority

Requirement: Python Function will read a LIST of TUPLES. The structure of the tuple is ("STRING", "STRING","STRING",INT,"GEOGRAPHIC VALUE") This Geographic value can have 5 values "zip", ...
1
vote
2answers
45 views

Matching lines in a CSV file with items in a dictionary

I was wondering if there was a better way of writing this... I have a CSV file (about 6640 lines). After reading through the file, the values for the DFN_Network ...
18
votes
4answers
1k views

Battleships game in Python

The idea is, you enter an amount of ships, for example 10. It will then place 10 ships on a 10x10 grid (0-9). You may enter a coordinate, and it will tell you if it is a hit or a miss. A simplified ...
1
vote
2answers
41 views

Class inheritance testing

I'm just messing around with class inheritance. I originally had a separate goal in mind but I ended up here, and my new goal was to have a parent that was completely ignorant of it's self, i.e. no ...
3
votes
0answers
43 views

Analysis of TV station preferences for various demographic groups

I have a notebook here which details my code and may be more legible. I worked on a project that flattens a table that initially looked like this (this is table1): ...
1
vote
1answer
96 views

A basic pure Python hash map using a tree

I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key. Can you help me understand, ...
-2
votes
0answers
44 views

FFT with Frequency Peak Output [closed]

This code performs fft using scipy as intended. The phase angle is also found along with the maximums that correlate to a frequency. The problem is that one or two of the frequencies calculated by ...
5
votes
2answers
94 views

BF interpreter in Python that uses recursion to handle loops

I wrote a Brainfuck interpreter in Python and I'm wondering how to simplify it. I handle separately loop commands and the others. A recursive function deals with loops. ...
1
vote
0answers
101 views

A mobile phone troubleshooting program [on hold]

The code should ask the user multiple solutions and find the problem with the user's phone. The program should be efficient as possible and have a possible of 10 outcomes. I would like some tips on ...
2
votes
1answer
46 views

Texas Hold'em classes

I am working on a simple Texas Hold'Em dealing simulator. I am new to Python and was hoping to get some advice on my use of classes here. I feel like I am not using them as efficiently as possible, ...
7
votes
8answers
1k views

Printing future leap years

My code prints the next 20 leap years: ...
2
votes
2answers
39 views

Copy directory to multiple directories - I/O performance matters

I am working on below python copy utility that should work on windows & linux, But I am looking for a more efficient approach that could optimize my I/O correction, as my target location is ...
2
votes
1answer
40 views

Associate an object with a regular expression in Python

Is there a way I can link/associate an object (in this particular case a function) with a regular expression pattern? Here's the function I'm working on: ...
-5
votes
0answers
39 views

Dice game finished - Please some (W)eedback :) [closed]

Im done with my DICE-GAME that i've made. I would like some feedback from you people CODE: http://pastebin.com/gXRiVKms
10
votes
5answers
797 views

Finding two consecutive triangular numbers with a given target sum

I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
-3
votes
0answers
25 views

Comparing performance of different ways of filtering in python [closed]

I'm trying different ways of filtering to see which has the best performance. I'm surprised that list comprehension is by far the fastest. This is under python 2.7: ...
4
votes
1answer
54 views

Solution to the 0/1 knapsack in Python

So I made a version for the 0/1 knapsack problem myself (using matrix dynamic programming algorithm). Given a list of items with name, value, and weight, my function computes correctly the optimal ...
3
votes
2answers
81 views

Python guessing game

I'd like some feedback. ...
0
votes
1answer
29 views

Comparison of incoming error strings to known set and transformation into 3rd string

I have a function where I am comparing an error string returned from a web service to several lists of known strings, and then based on which list the error is a member of, returning from the function ...
4
votes
2answers
71 views

Reversi (Othello) in Python

I'm a beginner-intermediate programmer who's mostly used Java. I taught myself Python and made this engine for playing Reversi. Tips on Pythonic ways to accomplish tasks and/or general advice ...
3
votes
1answer
57 views

Find position of a word in a list in Python

The aim of this program is to say which position a word is in a list. This is just a basic version of it. I made to see if I could shorten it more than what it is currently. ...
4
votes
1answer
39 views

Conway's Game of Life in Python, saving to an image

I have attempted to make conways game of life in Python, and then save the output into a picture. Is there any way to make this more efficient? Is there anything wrong with the logic? (Most of the ...
1
vote
2answers
55 views

Moving around in a 2D grid

Please tell me ways I can improve this code to be more efficient. ...
4
votes
3answers
37 views

User ranking system

I have written my first code of object oriented Python. Prior to this I have spent a week on learning the concepts and understanding the technique. I would appreciate it somebody reviews this and give ...
1
vote
1answer
85 views

Find median of two sorted arrays

Problem statement There are two sorted arrays nums1 and nums2 of size m and ...
4
votes
0answers
53 views

Creating a count inversion array of an unsorted array of unique integers

Given an array: arr = [2,3,1,4] I could write a count inversion array such that counting all numbers n2 after a certain ...
0
votes
1answer
48 views

Triple for loop for a data set

I am writing a triple for loop in Python. Since the data set is larger, it takes more than 1.5 hours to finish. Is there any fast way to avoid the loop? ...
2
votes
1answer
76 views

Noughts & Crosses

This is my first ever program in my first language, Python. I wanted to know how I could improve my writing style. ...
1
vote
1answer
39 views

Python CSV reader

I have a function that pulls data from a file or string literal in my case and returns them in either a list or a dict. My ...
2
votes
1answer
27 views

Python - insertion sort

Series post - I am reading through Introduction to Algorithms, 3rd Edition implementing each algorithm as I read them. Pretty basic insertion sort. Only considering numbers initially - how could I ...
-1
votes
2answers
40 views
-1
votes
2answers
50 views

Maths quiz with difficulty levels and a score database

How can I make the saving to the dictionaries more efficient as well as making my overall code more efficient? ...
-2
votes
1answer
139 views

On Finding Coin Jams

The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...