Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
3
votes
1answer
189 views

Review for Python mapping container in which every element is a key

I wanted to have a python container in which every element is a key (like in a set), but still supports mapping (like a dict) between the elements. To get a container which supports this idea the ...
14
votes
2answers
19k views

Converting Roman numerals to integers and vice versa

...
1
vote
1answer
199 views

CyberFaze app for Facebook

I had an efficiency problem like I thought and I didn't have the best solution here. My solution was \$O(n)\$ and directly a more experienced member told me a solution that is \$O(1)\$, that only ...
2
votes
1answer
274 views

Modularizing this file to make it more convenient and more readable

Background is this question and to create something like Craigslist or olx.com i.e. classifieds advertisement webapp / site and I've basically solved the problem and had a mess of unstructured code ...
3
votes
1answer
3k views

Collections.Counter in Python3

Can you suggest how I might make the following code more efficient: ...
-1
votes
1answer
2k views

ConfigParser inexisting file exception [closed]

Since Python's ConfigParser does not throw an exception if the file does not exist, is it fine to do it this way: ...
2
votes
1answer
3k views

Is this a safe/correct way to make a python LogHandler asynchronous?

I'm using some slow-ish emit() methods in Python (2.7) logging (email, http POST, etc.) and having them done synchronously in the calling thread is delaying web requests. I put together this function ...
0
votes
1answer
404 views

The logic for re.match() , sys.exit(1) does not make sense, plus why can't i use return True if the re.match regex matches [closed]

The whole idea behind this ,is the user enters : 1. hg commit -m "NO-TIK" and is able to submit the changeset 2. hg commit -m "NO-REVIEW" also does the same as # 1 3. hg commit -m "JIRA-123 blah blah" ...
5
votes
1answer
194 views

Faster tests with dependency analysis

I have a performance issue causing test->code->test cycle to be really slow. The slowness is hard to avoid, since I am doing some heavy image processing, and I am trying to accelerate things a bit by ...
2
votes
1answer
336 views

Gentoo linux updates notifier

This is my first experience of creating a useful tool in Python. I'd appreciate any critics on this. I can also post the config file if needed. ...
6
votes
3answers
18k views

Pythonic split list into n random chunks of roughly equal size

As part of my implementation of cross-validation, I find myself needing to split a list into chunks of roughly equal size. ...
6
votes
1answer
8k views

Snake game in Python

I am a biologist. Some time ago, I wanted to learn to program, and since I am fascinated by the 4th dimension and I was fascinated by the rotatation of hypercubes and hypersphere, so I decided to ...
3
votes
1answer
2k views

Koch Curve algorithm in Python without using Turtle/Logo logic

Inspired by the motivations expressed in this question. I created some code to generate the point list (and also display a pretty picture) using just analytic geometry (no Logo/Turtle, no ...
6
votes
3answers
5k views

Python list comparison: Can this code run faster?

The idea is to apply some function on each element in each list, then compare two lists by the value returned by the function. My current solution works but is not fast enough. running "python -m ...
2
votes
1answer
6k views

XECryption encryption and decryption script

The encryption script: ...
5
votes
2answers
603 views

just implemented multiprocessing and queue demo, wonder if there are any improvements?

i will give a list of urls, and want to make multi processes to fetch certain url's web content, and quit if all the urls are all fetched. here is my implementation, and not sure if it's the right ...
0
votes
1answer
2k views

Moving average of a data series

How can I rework the code up that ema(x, 5) returns the data now in emaout? I'm trying to enclose everything in one def. Right ...
3
votes
1answer
4k views

Very slow Python Combination Generator

I have the following function: ...
4
votes
4answers
4k views

Singleton Decorator

I've written a class that makes writing singletons easy. The class is meant to be used as a decorator (example below). I'd like to see your thoughts about the code, the documentation, and everything ...
2
votes
1answer
109 views

Matching and enumerating the results of a quiz [closed]

I was told that I might get some feed back about the code below. I'm learning and need some criticism. My initial question was how to save users answers and tally them up to display number correct/...
5
votes
1answer
288 views

Wrapper around a Python API for creating user interfaces

I am writing a wrapper around the GeUserArea class of Cinema 4D's Python API to enable creating user interfaces using an object orientated interface. I've already ...
4
votes
1answer
1k views

Wrapping bound methods

I've written this small class in Python that wraps bound methods but does not prevent the deletion of self. Do you have any thoughts on my code? Do you think I handle errors appropriately? Is it ...
0
votes
1answer
219 views

Iteration and memcache for selected categorized random elements

The following code is a quick implementation since I only needed 3 random images sorted by category (a random eyes image, a random nose image and a random mouth image and then combine them): ...
5
votes
1answer
591 views

My python hook for mercurial

In our hg workflow we use default as testing branch and stable as the one that contains stable code. All changes are made in ...
2
votes
2answers
4k views

finding definite integrals in Python using Trapezium rule

I wrote this program which finds the definite integral of a function. Where in the program could I optimize this code: ...
16
votes
2answers
1k views

Python Manga Image Viewer

I'm currently making a manga (read: comic) viewer in Python. This project has been a code-as-you-learn project, because I have been trying to code this as I learned about Tkinter. Python I have known ...
2
votes
6answers
4k views

Quadrant Queries challenge

Running the same test 10,000 times with cProfile tells me that most of the damage happens in the count() function. This is my attempt at a solution to the Quadrant Queries challenge from ...
7
votes
1answer
484 views

Code Review of small scientific project, particuarly array vs. list perform

I'm new to python but not to programming in general. This is my first project beyond the basics. I was wondering if I could get some feedback on the code in general, in particular on any bad Java/C++ ...
4
votes
2answers
11k views

Program to count the number of lines of code

I need to get this program reviewed. It is counting the lines of code in all files in the given directory. I'm new to python and need some advice on pretty much everything. ...
8
votes
3answers
4k views

Is there a better way to implement this Huffman Algorithm in Python?

I have written this implementation of Huffman coding. Please suggest ways to make this code better, i.e. more Pythonic. ...
6
votes
3answers
365 views

Add lister class

I feel a need to rewrite a rather large Python class that "does its job" but it looks somewhat terrible since it was pasted together while learning Python and the platform Google App Engine. It works ...
3
votes
1answer
1k views

Memory leaks in lottery simulator

I'm primarily a C++/Java programmer, but I've recently started using Python at work and decided to write a Lottery Simulator at home. I wrote it to test out different combinations of lottery numbers ...
3
votes
1answer
2k views

wxPython Form Builder - Sizer Automation

Presented for critique are a pair of classes which automate Sizer Creation and Layout in wxPython. ...
3
votes
1answer
174 views

Elixir db model

I have designed this model which is very flexible. For example, you can create asset types, assets and combinations of them infinitely. It is the front end to a Python Pyramid website, so all the ...
4
votes
2answers
873 views

Optimizing this 'print up to the nth prime number' script

I've been seeking to optimize this algorithm, perhaps by eliminating one of the loops, or with a better test to check for prime numbers. I'm trying to calculate and display 100000 prime numbers has ...
2
votes
2answers
2k views

Rolling loop with an array of data points

I have a NumPy array of about 2500 data points. This function is called on a rolling basis where 363 data points is passed at a time. ...
3
votes
2answers
474 views

A large number of math type equations and functions in a python module

I have roughly 40 or 50 functions that are similar to the one provided by the code below. I kept all the common calculations between multiple functions separate such as ...
5
votes
2answers
1k views

Discrete event simulation with variable intervals

I've built a discrete event simulation system, similar to the bank problem presented on the wikipedia page but with a key difference. Let's say, that a TELLER can ...
3
votes
2answers
340 views

Simple Function in python [closed]

I was wondering if this code can be coded better in terms of semantics or design. Should I return the LOS as numbers? should I have the constants be read from the db in case the user or I want to ...
2
votes
1answer
5k views

Parsing and data presentation in Django

For some time now, I've been using a pattern which I think could be done more elegantly. I have a lot of XML files that need to be represented in a Django views. My current approach is like this: I ...
3
votes
1answer
16k views

XML schema parsing and XML creation from flat files

I am new to Python and had to create a schema parser to pull information on attributes and complex types, etc. and then convert data from flat files into the proper XML format. We are processing a lot ...
3
votes
2answers
620 views

Brace pairing ({}[]()<>) cleanup/speedup

This is working as expected, except in the speed area + I need to make it more readable and shorter if possible, I probably have lot's of things I don't need :). Edit it is working now ...
2
votes
3answers
224 views

Django view function

I have a view function that allows a user to Add / Edit / Delete an object. How does the following function look, and in what ways could I improve it? I was thinking about separating aspects of the ...
6
votes
5answers
6k views

Converting a csv to vcards in Python

Context: I wrote a simple as an answer to a problem in Unix.SE and it was suggested to me to post it here for review. A comma separated file is generated by an application. On the first column it ...
4
votes
2answers
314 views

Social network evolution

I am writing a piece of code which models the evolution of a social network. The idea is that each person is assigned to a node and relationships between people (edges on the network) are given a ...
6
votes
5answers
9k views

Calculating the maximum drawdown of a set of returns

I wrote a simple function that calculates and returns the maximum drawdown of a set of returns. I am trying to squeeze as much efficiency for speed out of the code as possible. I've got it down to ...
4
votes
2answers
2k views

Single pass algorithm for finding the topX percent of items

I'm looking for a single-pass algorithm for finding the topX percent of floats in a stream where I do not know the total number ahead of time ... but its on the order of 5-30 million floats. It needs ...
7
votes
5answers
1k views

Holding records using dictionary

Can you please help me with the following script? At the moment the script is taking up to 20 mins to execute, depending on the amount of data being processed (each time the script is executed, it ...
0
votes
2answers
2k views

Command line tool for extracting, searching, and converting

I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this ...
1
vote
1answer
224 views

Parsing XML file containing some events

I'm a beginner and have written my first Python module that parses a XML file containing some events and prints them out to stdout as JSON. I would appreciate some ...