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

learn more… | top users | synonyms

0
votes
1answer
16 views
3
votes
2answers
55 views

ASCII-fication of playing cards

I am making a small Blackjack game in Python 3. The part of the code I am unsure about is that which allows me to print nice ASCII versions of the card. ...
2
votes
1answer
19 views

Designing unit tests for paramiko wrapper

Before I get to the question, let me note that I'm a trained scientist, not a programmer; I've done my best to self-teach what I've needed to know so far, but in the interest of making my code usable ...
4
votes
1answer
31 views

Optimizing critical loop for consuming a byte-buffer

I'm currently developing an Open Source project called sims3py using Python2.7. One overarching goal of the project is to ensure a Pure Python implementation of functions currently available only ...
0
votes
2answers
162 views

Assigning movements to counters for a board game, using die rolls. [on hold]

I have finished writing a program, and was wondering if I could make it any more efficient or generally more sophisticated that the current version. The below section of code is where I think ...
3
votes
2answers
59 views

Averaging lists of values with duplicate keys

I have gene expression data that I represent as a list of genes and a list of lists of values. I average the expression data for any genes with the same name. For example: ...
4
votes
2answers
45 views

Tic Tac Toe Game Sequence Generator

I want my code to write to a .csv file a bunch of patterns for Tic Tac Toe games (30000). I want to have 9 columns numbered 1 through 9 and in each have the number of the space in the grid that was ...
6
votes
3answers
229 views

Manipulating CSV files to regular text file

At my job, often I have to manually convert *.csv Files structured like: number,number\n number,number\n number,number\n ... To a regular *.txt file with the ...
3
votes
3answers
194 views

Finding the next palindrome code

I have been trying recently to develop a code finding the next palindrome from a certain number. For example, if the input is 800, the output should be 808, as 808 being the next palindrome from 800. ...
1
vote
1answer
28 views

Add sorting to a namedtuple

I currently override the sorting methods provided by namedtuple by doing something like this: ...
0
votes
2answers
27 views

Three Cards Trick - Assigning random number to the cards

At first I have three cards like this: ___ ___ ___ | | | | | | | A | | A | | Q | |___| |___| |___| and then I shuffle them to this: ...
2
votes
2answers
46 views

Split a list into a dictionary

I am trying to split my list into a dictionary and I wrote a function for it. It takes in a list and gets the list length. If the length of the list is 253 , it creates a dictionary with 26 keys - ...
1
vote
0answers
10 views

Removing Graph Nodes of a Specific Type and with Exactly Two Neighbors

Problem Description I am working with an undirected, weighted graph. It contains two types of nodes, called "A-type" and "B-type". I am starting with a set of ...
3
votes
1answer
52 views

Travelling salesman using brute-force and heuristics

I have implemented both a brute-force and a heuristic algorithm to solve the travelling salesman problem. ...
1
vote
1answer
22 views

Reading HTTP response from UART

I'm using a Telit GE864-GPS modem, which runs a dialect of Python 1.5.2. The Python module has access to the modem using a buffered UART, which may still be receiving when reading starts. The ...
5
votes
1answer
91 views

Efficient Pandas to MySQL “UPDATE… WHERE”

I have a pandas DataFrame and a (MySQL) database with the same columns. The database is not managed by me. I want to update the values in the database in an "UPDATE... WHERE" style, updating only ...
4
votes
1answer
61 views

Dictionary with restricted keys

I'm currently building some software that works with systemd unit files, and I've been trying to improve how we construct the unit files. This is all running in Python 3.4 This first block is the ...
2
votes
0answers
28 views

Perform additional tests before waiting for an event

I was looking for a way to perform additional tests before waiting for an event: if everything_is_alright(): event.wait() But this is not thread-safe. A ...
4
votes
1answer
83 views

Fizzbuzz in Python

I'm new to Python and wondering what can be improved with the following super novice program - in terms of the solution and code style etc. test_fizzbuzz.py ...
1
vote
1answer
38 views

Partial implementation of parsing a config-file and command line options

I need to be able to accept some options from either the command-line or a config-file. This code is a snippet of the class that I am working on, I cannot post the entire class here. This code works, ...
5
votes
3answers
87 views

Finding number pairs where the sum of their divisors are each other

Given a limit \$n\$, find all the pairs of values less than, or equal to n, which have the the property: ...
1
vote
2answers
344 views

Failing fast by raising an exception with a custom message

This is a script that utilizes lazy exception throwing. What I do is decorate a function that might throw an exception to throw an exception with a formatted string. ...
2
votes
1answer
38 views

Latitude/longitude waypoint distance calculations, crosstrack, VMG, ETA, etc

I'm in the process of a complete re-write of a stagnant and ill-conceived project. I would like some feedback on the following Python 2.7-3.4 code, before I go any deeper into it. I would hope it is ...
4
votes
1answer
43 views

Converting xy coordinates to theta without discontinutities

This one is, or rather, should be, fairly simple. I have a list of tuples of XY positions, and am trying to pull out angles relative to the origin from it. However, unlike ...
0
votes
0answers
20 views

Interactive Rock Paper Scissors

I am a beginner in programming and this is the third program I've written. This is an interactive game of rock, paper, scissors, capable of being modified to any number of turns. I would love to see ...
1
vote
2answers
71 views

Counting adenine and cytosine bases

I've started a little challenge on a website, and the first one was about counting different DNA letters. I've done it, but I found my method very brutal. I have a little experience, and I know that ...
8
votes
2answers
776 views

cm-to-inch calculator

After a few pages reading Learning Python Hard Way, I've decided to try to make a simple cm-to-inch calculator. I am very excited about this achievement, and I want someone to check my code. It works ...
-1
votes
0answers
15 views

Subtle error in calculate polygon centroid function? [closed]

Here's a function I have to calculate the centroid of a polygon, based on this document: ...
5
votes
1answer
143 views

10-faced dice-rolling game

My code is for a 10-faced dice-rolling game. There are 2 players who start off with 50 points, then they both roll a dice and get a random score between 1-10. The player with the highest roll gets the ...
4
votes
1answer
52 views

Class-based user input validation

Having contributed to this Community Wiki on StackOverflow regarding validating user input, I thought I'd finally sit down and write something more robust to do these kinds of tasks. I wanted ...
4
votes
3answers
116 views

Functional programming approach to repeated function application

Control like if..else and while If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the ...
8
votes
3answers
146 views

Adding two roman-numeral inputs

This is the first coding class I've taken and I'm not getting much feedback from the instructor. The function of this program is to take two roman numeral inputs, convert them to arabic, add them ...
-2
votes
0answers
14 views

Functions with arguments and paramaters [closed]

I'm taking this programming class and one of our assignments is to make a quiz and return right and wrong answers. So I've coded it all and the only thing that seems to be wrong is my passing of ...
4
votes
4answers
23 views

Indenting a function to recursively find filenames

I wrote this function that recursively traverses a given directory resolves the relative file-names to absolute file-names and yields the resolved file-name if it matches a given pattern. You can ...
2
votes
1answer
46 views

Checking for duplicate values in database with Python

I'm working on a Python application where I read and extract data from an HTML file. The data is stored in a list, and the number of items in a list is, on average, 50,000+. The items from the list ...
3
votes
2answers
49 views

Factorisation code running slow

I'm still in the process of learning Python and am doing some of the Project Euler problems. I have made a factorisation algorithm that works; however, it runs really slowly, and I'm not too ...
6
votes
0answers
28 views

Block_breaker clone in pygame with simple edge detection

I tried to make this clone of brick_breaker on my own in one day. However I have some concerns about the code so far: It uses simple edge detection code (as if ball goes out of screen <600 or ...
3
votes
2answers
63 views

Summation and product functions using functional paradigm

Below is the problem: Show that both summation and product are instances of a more general function, called accumulate, with the following signature: ...
1
vote
0answers
29 views

Correct, DRY, and efficient use of Django Managers?

I'm writing a custom Manager for my django app that lets you group django-enumfields: ...
2
votes
0answers
10 views

Mimicking Django filter function

I really appreciate the way filtering is applied to queries in Django. I have a list of items (each item is an Item instance which contains a few attributes) that I ...
6
votes
1answer
372 views

Is using the result of cmp() as an index “too cryptic”?

This is a very subjective question, but I'm curious as to other people's opinions. Would you find this bit of code distasteful? Is it cryptic and unreadable, or is it using features of the language ...
7
votes
3answers
99 views

Replace keys in values with key->values from same dictionary

I have a dictionary whose values may contain keys that are already in the dictionary. What we are actually talking about are parameters. Sometimes a parameter is defined by a number plus another ...
3
votes
1answer
56 views

Divide all elements in the column of a sparse matrix

Using Python Scipy, I am trying to divide all numbers in all columns of a sparse matrix (400K × 500K, density 0.0005), by the sum of the squares of all numbers in a column. If a column is ...
1
vote
0answers
29 views

CAPTCHA reader and maker

I've made some CAPTCHA reader and maker in Python using Tkinter. Do you know if it's possible to keep image and output files in "memory" not writing them on disc? Because right now everything is ...
4
votes
1answer
58 views

Script to generate documents based on conditionals and CSV data

I wrote this script a while back to generate press releases. It consumes a csv of data where each row contains the data for a country and fills in values in pre-written text based on the data. In its ...
5
votes
2answers
35 views

Validating config files and separating back-end from front-end

I'm writing a simple script which will search a source directory for certain types of files and move them to a destination directory. I'm using it as an opportunity to practice writing some ...
7
votes
1answer
53 views

Python script audibly represents itself

I was just messing around with python making wav files; when I came up with this (what I think is) pretty neat script. It takes each character and represents it ...
8
votes
2answers
166 views

Symmetric Square

I was given an assignment to ensure that a list was symmetric. I built it in a way that worked and it passed the tests. But I wanted to see if it could've been written more efficiently and still ...
5
votes
5answers
648 views

Simple Rock, Paper, Scissors in Python

I have looked at many different approaches to this game online, but as someone who isn't very experienced with Python, I may not be aware of what others are doing right. Here is my code: ...
2
votes
1answer
35 views

K-means clustering algorithm in python

Here is my implementation of the k-means algorithm in python. I would love to get any feedback on how it could be improved or any logical errors that you may see. I've left off a lot of the ...