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

learn more… | top users | synonyms

4
votes
0answers
9 views

Resource-constrained project scheduling

I'm trying to implement an algorithm for a resource-constrained project scheduling problem. I have several resources, resource constraints and all of this is in ...
3
votes
1answer
22 views

Disjoint-set data structure in Python 3

Inspired by this question, I decided to implement a Disjoint-set data structure in Python 3. I mainly followed this description for understanding the algorithm (but did not do the optimizations for ...
2
votes
0answers
38 views

Websocket-based server for Raspberry Pi

I am trying to build a websocket server to run on the Raspberry Pi. The websocket server has to push periodic realtime update to a browser. Here is a sample code that I am planning to use. The example ...
0
votes
0answers
8 views

Using popup window to get user inputs and use those inputs in button's function in OpenERP

I would like to ask community to evaluate my solution in OpenERP. I am using Odoo v8. I have created a popup window with two fields, original_code and ...
2
votes
1answer
57 views

Little command line video grabber

I made a little Python3 script to grab video clips from a website for viewing off-line later and would like your critique, advice, tips & tricks and/or learning resources to create better code. ...
-3
votes
0answers
19 views

Python csv calculate percentage by group [on hold]

I have a table (csv file) with three columns (See 1) My Aim is to calculate the percentage of wood for each Polygon. I want to print this result into a new csv table (See [2]) I usually use Python ...
1
vote
1answer
14 views

Expiring in-memory cache module

I needed a simple expiring in-memory cache module for a project I'm working on and I've come up with the following. My requirements for the cache module are: Be able to expire objects after certain ...
-3
votes
0answers
15 views

understanding the flow of code to get particular parameter value [on hold]

I am working on data processing where I send parsed sentense as a input and get relations and entity. It also calculates score ...
2
votes
1answer
40 views

Solution for puzzle 3d x 1d = 2d x 2d in Python

I wanted to resolve the puzzle from this link using Python 3. It works and gives me the correct value but I would like to know if it is possible to resolve this problem with a few lines or how I can ...
1
vote
2answers
63 views

Cleaner code for classes

I am trying to make my class a bit cleaner, especially some of its methods like Count, __add__, ...
1
vote
0answers
18 views

Optimize Python script for generating Point Cloud

I'm trying to produce a 3D point cloud from a depth image and some camera intrinsics. The image is 640x480, and is a NumPy array of bytes. The output is a (rows * columns) x 3 array of points. I've ...
2
votes
0answers
50 views

Dijkstra's algorithm in Python

I was hoping that some more experienced programmers could help me make my implementation of Dijkstra's algorithm more efficient. So far, I think that the most susceptible part is how I am looping ...
1
vote
1answer
6 views

Improving genetic algorithm fitness function

I'm attempting to speed up my genetic algorithm that modifies images. After searching, I've found that my fitness function is the bottleneck, taking sometimes up to ...
1
vote
1answer
23 views

Parse a config-file and add to command-line-arguments using argparse in Python

I am trying to parse the command line arguments using argparse, and if the user specifies a yaml file for the config-file, add those arguments to the args from argparse ...
0
votes
0answers
16 views

How can I make this nested loop more elegant? [on hold]

This python code works, but it is unbelievably ugly. Can anyone think of a more elegant way to do perform the loop management? I took out all the details from what the loop is actually doing and just ...
5
votes
0answers
37 views

Modeling a Mage character from nWoD, using Django

Goal Design a representation of a mage character from the World of Darkness RPG, as well their associated spells. I haven't used proper UML notation for the relationships (arrows etc.) but ...
2
votes
1answer
30 views

Python object modelling with ABCs

I'm modelling the core entities in a callcenter-related system that deals with Operators and groups ("pools") of them. While I've written some Python before, this is my first time building a larger ...
0
votes
0answers
23 views

How to get elements of list in a defined order in python? [on hold]

I have a list like this: list = ["Resttorf","T12/14 Frastorf","T16 Frastorf","FBP16 Baggertorf","E Sodentorf","E Frastorf","S8/10 Frastorf"] I have to organise ...
5
votes
3answers
85 views

Tree structure with support for inorder and preorder traversal

I am learning Tree Data Structures and came up with this code for implementing basic Tree Node using class and performing various Tree based operations like Traversals and others. The code works ...
1
vote
1answer
34 views

Python decorator for optional arguments decorator

I want my Python decorators to have optional arguments and not be called when not necessary. The accepted answer in here doesn't accept named arguments, and I don't want to add boilerplate code ...
3
votes
0answers
18 views

Identifying surface events happening at specific time intervals

Here is some code I wrote to surface Mint.com transactions that occur at monthly intervals, in order to identify subscriptions I may be paying for without realizing it. I'd like to have some friends ...
-2
votes
0answers
18 views

Convert to Threading and Queues? [on hold]

I'm looking to convert this working code to threading and queues instead of thread and global variables, but am not understanding how to do it. ...
2
votes
0answers
37 views

Pure Python script that saves html page with all images

Here is pure Python script that saves html page without CSS but with all images on it and replaces all hrefs with path of image on hard drive. I know that there are great libraries like ...
2
votes
1answer
40 views

Use of dictionary for file-saving function

I have the following function: ...
3
votes
0answers
37 views

Project Euler module

I use Project Euler to teach me programming and not to submit any results. As such I look up the expected return values to double check my solutions. To organise my files I use the following folder ...
1
vote
4answers
68 views

Coupon collector

This is a coupon collector code to analyze the running time. I need some suggestions on improving the running times of this code. I have used the data structure dictionary, but is there any other data ...
1
vote
1answer
33 views

Filtering stocks by dividend yield

I have a dict of stock tickers (KEY) and a data point (VALUE; e.g. dividend yield). I want to know which tickers have a value between a specified min and max value. Given ...
4
votes
3answers
44 views

Searching for a string in a downloaded PDF

This code goes to the website containing the PDF, downloads the PDF, then it converts this PDF to text. Finally, it reads this whole file (Over 5000 lines) into a list, line by line, and searches for ...
2
votes
1answer
56 views

XOR of a list of a numbers

In preparing a solution for the CodeChef "Will India Win" challenge, I am trying to find out the xor of list of numbers. The first line of input contains the number of test cases, 1 ≤ T ≤ 106. ...
2
votes
2answers
21 views

Create SQLite backups

I have this script for creating SQLite backups, and I was wondering whether you'd have any suggestions on how to improve this. I was thinking that maybe it should create the backup ...
3
votes
3answers
92 views

Pouring water between two jugs to get a certain amount in one of the jugs

I wrote a solution for a jug problem (given two jugs of water of different sizes find the steps needed to get specific amount of water in one of the jugs). I'm hoping for some input on my code. How ...
1
vote
4answers
182 views

Depth-first search in Python

I wrote this DFS in Python and I was wondering if it correct. Somehow it seems too simple to me. Each node is a class with attributes: visited: Boolean ...
5
votes
2answers
192 views

Cleaner code for iterables

I am new to Python and am trying to see if there is a cleaner way to write my code. The following code take iterables as parameter it produces the first value from the first parameter, then the first ...
5
votes
1answer
53 views

OO Blackjack game design

I have set up card, deck, hand, player, ...
2
votes
1answer
30 views

All-in-one number base converter

I coded this program as a challenge for /r/dailyprogrammer. Basically this program can convert any number from any base to another base including negative bases as long as the input is coherent. Did I ...
-3
votes
0answers
30 views

Style: python if else in one line [closed]

I tend to use something like this: result = -1 if some_condition else result I use it very often in a return statement like ...
8
votes
2answers
61 views

Encoding and decoding small strings of text

This is supposed to encode and decode small strings of text. Unfortunately, even on a really good laptop, it performs slowly. This might have to do with my looping, or just the sheer computation. It ...
4
votes
1answer
66 views

Universal memoization decorator

I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with. So, if, say, we ...
3
votes
3answers
85 views

Project Euler 35: Circular primes below 1 million

I'm doing another Project Euler problem, number 35, and I need help improving my code speed: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
11
votes
1answer
165 views
+100

Day Planner / Logger

This is a simple program I've made using Qt Creator and Pyside: I made a list of activities that I would like to enforce; Then I made a program that randomly pick them based on chance; It has some ...
4
votes
0answers
53 views

Visualize Parts of Song as Analyzed by Echonest

This is the a bit of code that works with Echonest API's pyechonest and remix libraries combined with matplotlib.pyplot to offer a simple visual representation of the start and end "parts" of a music ...
3
votes
3answers
98 views

Converting click count data to JSON

I have an array filled with 5 other arrays that consists of arrays of 2 values (first a date then a count): ...
4
votes
0answers
46 views

Finding cycles in a graph that pass through a vertex at most k times

I have a project that relies on finding all cycles in a graph that pass through a vertex at most k times. Naturally, I'm sticking with the case of k=1 for the sake of development right now. I've come ...
5
votes
3answers
140 views

Optimize huge text file search

I have several huge 100MB text files that I need to scan through to pick out certain frame numbers which relate to a specific log packet of interest. My plan was to scan for these frame numbers and ...
3
votes
1answer
61 views

Extracting length-3 subsequences from a list

For a list li, I want to print only the values of the triplets a, b, c where ...
2
votes
1answer
27 views

Modeling and plotting neuron responses

I want to assign the row of a matrix the return value of a function, but the only way I can figure out how to do this is with a for-loop. I'm assuming this is bad ...
1
vote
1answer
33 views

Moving window with complete boundary in Python

I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example: ...
1
vote
1answer
50 views

Calculating Euclidean distance and performing unit-testing

The method creates a link, an edge between two nodes, and calculates the Euclidean distance. I'm testing that after linking, the link does indeed exist, and that the distance is correct. I've used ...
5
votes
1answer
62 views

Simple encryption based on MD5

I made a Python 3(.4.2) program that only adds classes and is meant to be imported. It allows the creation of files that store usernames and hashed passwords. It uses salting as well. It also can ...
1
vote
2answers
55 views

Generate random unit vectors around circle

I'm trying to generate a bunch of uniformly distributed unit vectors around the unit circle. Here's my code, which is working, but unfortunately I have a for-loop. How do I get rid of this for-loop? ...