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

learn more… | top users | synonyms

1
vote
0answers
7 views

Python DictionaryTagger class takes too long to initialize

With big inspiration from code from different webpages, I have created this DictionaryTagger. My problem is that it takes around 2 sec. to initialize the taggers / ...
1
vote
1answer
41 views

“Guess My Number”, Alternative Edition

This is an alternative edition of a game I modified the code for. See: Guess My Number, Classic Edition I seek advice on best practice. Tips, tricks, and suggestions, all welcome: ...
5
votes
1answer
29 views

Making user menus in a text-based game

I'm new to Python and programming in general, but I'm making it work. I have this little game I've been working on as a learning exercise and I'm a bit concerned that I'm using far too many ...
-1
votes
1answer
68 views

Rewriting an ugly function

I have been recommended on stack to rewrite the function, but it does get the job done. Can I improve the efficiency or readability? ...
-1
votes
0answers
10 views

Python optimisation: np.where() v. [for x in [on hold]

I recently replaced statements like: x[np.where(np.cumsum(y[j, x])<=c)[0]] with ones like x[[i for i in x if np.cumsum(y[j, x])[i]<=c]] on the basis that the code might run more quickly. I ...
3
votes
1answer
37 views

Python wrapper for official Hacker News API

Since Hacker News launched their official API, I started working on Python wrapper for it. API v0 is fairly simple, you send a GET request with hacker news story's ID or user id, it returns data in ...
5
votes
1answer
48 views

Caesar cipher with GUI

I have created a functional Caesar cipher in Python 3 and I have implemented a GUI using Tkinter. ...
7
votes
4answers
563 views

Guess My Number, Classic Edition

I am learning Python at present, from several books. I am new to programming and I need assistance with knowing when my code is written with good form and style - I want to ingrain the habit of ...
4
votes
0answers
46 views

Eliminating duplication in Python native code function call dispatchers

I attempting to merge 3 functions into one, as they contain for the most part the same code. Here are the original functions: ...
2
votes
1answer
34 views

Print dict with varying-length lists

Is there a shorter way of taking a dict with varying length lists and printing it to screen? Shortcomings of this method also include that values which aren't lists are printed as letters separated by ...
1
vote
0answers
21 views

Optimise a spatial join for QGIS 2.0 Python plugin

I got a really great code review for a similar issue, but I seem to be unable to adapt it to another calculation for a QGIS 2.0 Python plugin. I am attaching field values to any features intersecting ...
4
votes
1answer
45 views

Kindergarten Garden challenge: ugly zip-group-flatten?

I wrote up a solution for the "Kindergarten Garden" problem on exercism.io. My class will be handed a string that describes two rows of plants. Each student (either in a pre-set list or given as ...
0
votes
0answers
12 views

Calculate azimuth of vector for QGIS 2.0

I calculate the azimuth of a vector and update a field in my QGIS 2.0 Python 2.7 plugin. This works currently, but it takes much longer than I'd like to. I believe it is because I'm querying the data ...
3
votes
2answers
68 views

Creating a list containing the rank of the elements in the original list

I don't really know how to explain what I'm looking for in a way that makes sense, but here goes: Say I have a list $$L=(4,7,9,10,6,11,3)$$ What I want to produce is a corresponding list $$ K = ...
0
votes
0answers
25 views

Creating exit in if loop? [on hold]

Im trying to create a quiz that posts random questions from the "library" called questions. After each time an answer is given, it should stop and ask if the user wants to continue. If it does not ...
-1
votes
0answers
26 views

Blackjack python code [on hold]

I need help making this code run for a school project on blackjack and I cannot figure out why its not running any help would be appreciated ...
3
votes
1answer
21 views

Unittests for CashFlow object

I'm just writing a small unittest to test for a hypothetical library and object, as a way of predefining the behavior, perhaps both as an acceptance test and for unittesting as well. As I'm writing ...
5
votes
1answer
55 views

Text adventure and global variables

I'm working on this little text based game. Up to this point, I've gotten it to work, however I've heard I shouldn't be using global like I am. I have this set up to modify the global variables ...
-3
votes
0answers
28 views

Rewrite custom query into django's query language [on hold]

I have this special method written by a friend and I don't know how to write it using django's query language. I want to order my Projects by the lowest datetime ...
0
votes
1answer
46 views

Python encapsulation [on hold]

From objective and functional standpoints, how can I clean this up so that it doesn't feel messy and hackish? ...
0
votes
2answers
49 views

Basic Python Calculator script [closed]

I am trying to write a program which implements a simple calculator using python. I am having trouble figuring out the simplest way of doing this (I'm a super beginner). I'm almost there but the ...
3
votes
0answers
29 views

Find binary sequence in NumPy binary array

As part of creating a software defined receiver and decoder, I want to find sync pulses in weather satellite data. The data is first digitized to a 0-1 array. The code below is working. The ...
4
votes
1answer
52 views

Regular expressions - match only specified string length

I'm learning regex. Here I'm checking a string of type aA1 but want also to check it is only 3 characters long. Is there a better way of doing it please? ...
2
votes
3answers
81 views

Optimizing run time of Python solution to Project Euler Problem 34

This is a brute force solution to Project Euler Problem 34 with only 1 optimization (i.e.: caching factorials): ...
1
vote
1answer
38 views

Crawl multiple pages at once

This an update to my last question. I want to process multiple pages at once pulling URLs from tier_list in the crawl_web ...
2
votes
0answers
27 views

Speeding up this tfidf vectorizer

After thoroughly profiling my program, I have been able to pinpoint that it is being slowed down by the vectorizer. I am working on text data, and two lines of simple tfidf unigram vectorization is ...
1
vote
1answer
25 views

Observing PEP maximum line size, particularly when formatting localized timestamps

I have this function that I use to publish a message but I need to do this long conversion for time and date. Maybe there's a better way to convert it to make smaller. Otherwise I'm stuck with this ...
2
votes
1answer
34 views

Clear cache files older than 30 minutes

This is what I came up with to delete files not modified within the last 30 minutes from a subdirectory named cache. ...
-3
votes
0answers
17 views

How to improve this piece of python code to run it faster

Here is the code. ...
4
votes
1answer
45 views

Filtering runtime processes to see if is a runaway process

I'm trying to improve readability and performance, either by reordering the logic of my code or just syntactically being smarter. Basically, I gather the running processes from Db and then I parse ...
1
vote
1answer
24 views

Sharing a database connection with multiple modules

I am building what essentially could be viewed as a glorified database wrapper as a Python package, where I'm having several classes and functions spread out into different modules. My current problem ...
-4
votes
0answers
47 views

Rewrite Python code in Java [closed]

I need help for rewriting Python code into Java. Unfortunately I know how to write Java programs but I don't have any experience with Python. ...
2
votes
0answers
20 views

Matplotlib-venn and keeping lists of the entries

Having come upon the wonderful little module of matplotlib-venn I've used it for a bit, I'm wondering if there's a nicer way of doing things than what I have done so far. I know that you can use the ...
2
votes
0answers
24 views

Is this way of creating dynamic Django Forms too cute? [closed]

In Django I sometimes have forms of which the number of fields can vary depending on circumstances. Maybe a field isn't shown sometimes in cases when it's not applicable. I usually create optional ...
3
votes
1answer
28 views

Primitive Python P2P Socket Chat

Here is my code for a Python script for a peer to peer chat system on a network using sockets. I know there are some things that could be changed so there would be less repetition in the code and ...
0
votes
0answers
44 views

Tkinter initializing method in class

I created a simple program that displays 28 numbers on the screen. Currently, nothing happens when you click on the numbers. Eventually, I want the numbers to disappear on click. Also, when you click ...
1
vote
1answer
35 views

Iterate over items in a set of dicts

I'm using the following code to initialise 8 I/O-ports (i.e. GPIO pins on a Raspberry Pi). That's 4 x 2 pins, each duo controls a switch, A to D, and each duo consists of a pin for On and a pin for ...
2
votes
1answer
27 views

Matching PEP8 style with long one line for loop

I'm working with Python 2.7.5 and I'm trying to make it match the PEP8 coding style. I have a few one line for loops but the issue is that they are each above 80 ...
3
votes
1answer
37 views

Threading and queue experiment

I'm just beginning to get the idea of queue and threading. I would welcome input on this exercise script: ...
1
vote
2answers
64 views

Code to generate a dictionary from two lists

I created a script to perform a union on 2 lists: keys and words. I needed to create a dictionary from them. If there are more keys than words, missing words are replaced with "None". Any excess words ...
1
vote
2answers
88 views

Basic search engine

I want to improve efficiency of this search engine. It works in about 10 seconds for a search depth of 1, but 4 minutes at 2 etc. I tried to give straightforward comments and variable names, any ...
2
votes
1answer
46 views

Conditional statements with doctor and patient information

I'm focusing on trying to write clean, modular Python 2.7.5 code. ...
2
votes
1answer
33 views

Speeding up a length calculation for a QGIS plugin

In a QGIS 2.0 plugin for windows, I calculate length and update a field with the values. It works, but takes a lot of time. Execution for this part only takes about ten minutes. Can anyone suggest ...
2
votes
2answers
32 views

Optimising and condensing Django View Class

This follows on from a previous question I asked which was of huge help to me. I am still only learning Python and Django and I would love to learn how to code better. The below is a ...
2
votes
2answers
52 views

Extracting maximum values from each of the subsets of an array

Problem description: I have a numpy array cps from which I want to extract the maximum value in each of the subsets of the array (a subset is defined as non-zero ...
5
votes
1answer
86 views

Transpose a large matrix in Python3

I want to transpose this matrix input: 1.000 2.00 3.0 4.00 5.00 6.000 7.00000 8.0000000 9.0 10.0 11.0 12.00000 And get this output: ...
10
votes
3answers
869 views

Displaying information about people from a JSON file

I'm working with Python 2.7.5 and I have written the following code: ...
2
votes
0answers
30 views

Text parsing and calculator (calculate Java heap memory)

I'm writing small tool, which must execute jmap -heap, write output to log, then takes some data from log and calculate used memory. I added some ...
5
votes
4answers
412 views

Scissors, Paper, Rock in Python

The game works, but I was wondering if anyone could help me with better structure for the code, simplification, or just any other improvements. ...
3
votes
2answers
56 views

Lingo Guess Game

I'm writing a program for a game called "Lingo": ...