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

learn more… | top users | synonyms

3
votes
2answers
52 views

Cycling time trials

It would be helpful to know where I could improve the style of it, so it follows the style guide better, and also any ways I could compact it - especially at the end, where I have added items to a ...
2
votes
2answers
67 views

Are my one-method (and a couple attribute) classes overkill?

I saw a talk by Jack Diederich a few weeks ago titled "Stop Writing Classes" and noticed that some of my code perhaps echoes what he argues against (to the effect of "classes with two methods, one of ...
5
votes
1answer
50 views

Monte Carlo estimation of the Hypergeometric Function

I am trying to implement the algorithm described in the paper Statistical Test for the Comparison of Samples from Mutational Spectra (Adams & Skopek, 1986) DOI: 10.1016/0022-2836(87)90669-3: $$p ...
2
votes
0answers
29 views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
3
votes
1answer
27 views

Making a webapp using Bottle

Here is a screenshot of my setup: Here is the actual code: ...
2
votes
0answers
25 views

Careful simulation of a 3D space [on hold]

What is an accurate computer-description of space? I've been building up my abilities with various population simulations, and I'd like to add a spacial element to them now. I'm self-taught with ...
5
votes
3answers
147 views

Caesar cipher exercise

I was doing this exercise from here. I made a solution work but can't help feel it could have been done in fewer lines. I'm quite new to python so I'm not too sure of the little shortcuts. ...
26
votes
4answers
1k views

Flappy Bird game clone for a beginners' programming class

I'll soon begin teaching a beginners' programming class. It's voluntary, so I thought I'd make it interesting by teaching Python programming and then introduce the kids to Pygame, so that they can ...
3
votes
2answers
56 views

Custom exit with only some exceptions in Python

I want to define an exit code for some exceptions and some exceptions only. I want that the only input is that dictionary with the definition. ...
3
votes
1answer
87 views

Interview task to efficiently find compact representation of nodes in tree and find big O time

I recently had an interview problem where I was asked to find a compact representation of nodes in a tree. As an example, consider the following tree: ...
2
votes
2answers
30 views

Basic value comparisons

I made a value comparison "programming language" similar to a previous one I made, except this one is based solely on value comparisons. ...
3
votes
2answers
49 views

Making this Python state machine more pythonic

Is there a replacement for the global? My goal is to have something really simple with as small an amount of code as possible. The real code is used to parse a text file of nested structures. ...
2
votes
2answers
65 views

Python script for making a table

I have written a Python 2.6.6 script in order to make tables by taking the third column of every text file in a particular subgroup (signal and background in this case[particle physics]). However, I ...
-2
votes
0answers
10 views

Python MySQLdb not refreshing database information [on hold]

I'm currently codiing a simple IRC moderator/utility bot. I plan to have a web interface that will easily update command data and whether or not the command is enable using a MySQL database to store ...
-2
votes
0answers
19 views

Python Code Correction [on hold]

def f(x): x = x + 1 print 'x =', x return x x = 3 z = f(x) print 'z =', z print 'x =', x Hi. I'm a noob at programming and started to learn in Python. A ...
7
votes
5answers
381 views

Python code for detecting a single item moved in a list

I need to write a function that takes an original list of unique values and a resulting list: [0,1,2,3] [0,3,1,2] and detect that only a single element was ...
2
votes
1answer
35 views

Are 2 Django URLs pointing at 1 view unorthodox?

I'm in the process of writing a private messaging system and I have 2 URLs which go to the same view (is that bad?). The logic behind this madness relates to the way user relationships are structured ...
2
votes
1answer
45 views

A function to convert FASTA .txt to a dictionary

I'd like feedback on my function to convert FASTA data to a dictionary in Python. Here's an example of FASTA text: ...
2
votes
2answers
133 views

HackerRank “Manasa and Stones” in Python

Problem Statement: Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference ...
5
votes
2answers
303 views

HackerRank “Service Lane” in Python

Problem statement: Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any ...
7
votes
1answer
82 views

Topological Sort and Graphing in Python 3

I wrote a program for DFS traversal, topological sort, find all vertices, and has_cycle methods. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to ...
4
votes
1answer
35 views

Thin proxy class for hashables

I need some kind of thin wrapper object to mark dictionary keys, like: d = { Required('name'): str, Optional('age'): int, } And these wrappers should behave ...
6
votes
3answers
107 views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...
-4
votes
0answers
25 views

Merge Sort Implementation in Python unorderable types [closed]

This merge sort implementation fails on this error: " if (left_list[0] <= right_list[0]): TypeError: unorderable types: int() <= list()." I know what the error means but I don't understand why ...
5
votes
1answer
63 views

Increase the speed of this Caesar Cipher

Here's my attempt at a Caesar Cipher encoder/decoder. If given a key, it will encrypt the given string. However, if you do not specify a key, it checks each of the 26 possible keys and returns the ...
2
votes
2answers
97 views

Project Euler 81 (minimum path sum through a matrix)

Problem Statement: In the 5 by 5 matrix below, 131 673 234 103 18 201 96 342 965 150 630 803 746 422 111 537 699 497 121 956 805 732 524 37 331 ...
-2
votes
0answers
20 views

Challenge to convert a simple IDL code into Python [closed]

Asking if someone can help me to convert the following IDL code into python: ...
3
votes
1answer
37 views

How to better indent multiline strings with many string formatting args?

I have a function, that is used in flask, for logging application errors: ...
1
vote
2answers
132 views

Grouping string to list of strings

The following is function that I have written to group a string to groups, based on whether there's consecutive repeated occurrence. Fop example AAAABBBBAAB is ...
2
votes
2answers
57 views

Mutual friends finder written in Python

I've written a server/client tool which can "check the Six degrees of separation theory" in Russian social network VK.com. Client sends task (which contains two VK IDs) and Server tries to find all ...
5
votes
1answer
91 views

Groupby in NumPy

To avoid the XY problem, here is an example of what I need. Given the sorted integer input array [1 1 1 2 2 3], I would like to produce the following slices, ...
1
vote
1answer
72 views

Getting rid of certain HTML tags

This code simply returns a small section of HTML code and then gets rid of all tags except for break tags. It seems inefficient because you cannot search and replace with a beautiful soup object as ...
4
votes
4answers
66 views

Refactoring huge if..elif in __init__ how?

I have this huge __init__ method, which is readable I think, but still doesn't feel right after watching Clean Coders videos (content of Clean Code book by Robert ...
4
votes
1answer
37 views

Stable partition in Numpy

In essence, I need to do a stable partition: All elements of the 1D np.array a that are present in ...
8
votes
2answers
305 views

Scrape an HTML table with python

I think I'm on the right track, but ANY suggestions or critques are welcome. The program just scrapes an HTML table and prints it to stdout. ...
6
votes
1answer
69 views

Agnostic means of identifying a member

I'm attempting to provide an agnostic means of identifying a member. I need a nickname, a guid, and one of ...
7
votes
1answer
108 views

Optimizing “Poker hands” challenge solution

I'm trying to solve the project Euler problem 54. In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest ...
5
votes
3answers
148 views

Project Euler #9 - Pythagorean triplets

This code works, and I'm trying to figure out if there's a better way to optimize it. As you can see, I've cut down drastically on time just by using numbers that work for ...
6
votes
1answer
117 views

Light Python pubsub lib, but is it too light?

In attempting to decouple the object from the messaging I came up with the following short code for adding publish-subscribe functionality to a Python script. ...
4
votes
3answers
76 views

Validate parameters within a range

Function to use several blocks of if:elif:else: that all take slightly different conditional statements. I'm trying to format integers into a 2 digit string, ...
10
votes
1answer
650 views

Battle a random enemy

I am trying to write a text adventure as my first Python project. For this segment, I wanted a random enemy (part of a class with its own attributes) to appear and then enter a turn based battle with ...
8
votes
6answers
856 views

Is it possible to optimize the following boolean checks?

The following code works and it prints out only True as it is supposed to, for all the different cases: ...
1
vote
1answer
45 views

Neighbours from point connections

I am working with a mesh of triangles (in 3D, although I doubt it makes a difference). The mesh is given as list of lists, each list containing the indices of the three vertices of a triangle in said ...
3
votes
1answer
33 views

CLI Command Search Tool - XML Framework

I'm working on the OSCP, and Information Security certificate based around penetration testing. CLI-based tools seem to be the core of most pen-testing assignments, so I'd like to build a tool aiding ...
3
votes
0answers
30 views

Parallelizing some model fitting code using multiprocessing

I'm trying to refactor some code for fitting parametric models that are defined symbolically using Theano. My goal is for all models to expose a common interface so that, as far as possible, they can ...
-4
votes
1answer
57 views

How to shorten Python Code [closed]

How to shorten the following line of code in Python if((post["datatype"][index]=="VARCHAR2" or post["datatype"][index]=="NUMBER")):
4
votes
2answers
81 views

Readable way to print a list of things in Python

I am trying to solve the common "print a character after every item in a list, except the last one" problem. I do not want to use list indices. There are a couple of simple ways to do this in Python, ...
2
votes
1answer
47 views

How can I make this implementation of Euler's method more efficient?

I have an implementation of an Euler method for solving N-many 1st order coupled differential equations, but I feel that I did not write it as efficiently as I could, due to lack of programming ...
15
votes
2answers
684 views

Avoiding Python multiline string indentation

I want to make this code: ...
3
votes
2answers
94 views

Group and send all files to filetype folder

I have around ~2M of files in one folder, which I need to manage. So, I want to separate them in groups by their filetypes. Example: filenames ...