Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
7
votes
4answers
146 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
37 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
27 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
19 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
40 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
8 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
62 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
22 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
22 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
20 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
50 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
46 views
Basic Python Calculator script [on hold]
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
28 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
49 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
80 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
36 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
25 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
31 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
13 views
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
45 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
26 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
34 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
61 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
87 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
44 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
0answers
18 views
creating prime factorzation [closed]
can any one answer what each line really means, I found this online, I am trying to teach myself python, I am not sure what it really mean.
def primo(n):
...
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
50 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
867 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
0answers
26 views
Python like “property” in Perl [closed]
I am fairly new to perl and I was wondering if there is a way to simulate python's property decorator in perl? After googling I have came across accessors and attributes but accessors are just ...
3
votes
2answers
56 views
1
vote
0answers
17 views
Elasticsearch save comments and submissions from Reddit
I wrote a script to save comments and submissions from Reddit using Elasticsearch
Is there any way to improve the speed of inserting new items into Elasticsearch?
...
7
votes
2answers
69 views
List files in a directory
I have folder1 that contains other folders (which may contain other folders etc). This process stops at some point where a folder contains only files, and some of ...
6
votes
1answer
79 views
Dict of names and birth dates which prints with age at birthday of current year
As a beginner (Learn Python the Hard Way), I've set myself this exercise with classes and it works but looks very inelegant to me. I'm trying to write classes which could be re-used in other code. ...
3
votes
3answers
78 views
Multi-replacement in a string, independently and prioritized
I need a shorter way to do this.
input: an ordered list of string pairs L; and a string s
task: for each pair ...
1
vote
1answer
55 views
Simple backup script
I haven't done much Python in the past, so I was wondering if you could look over my code and make sure everything is up to snuff?
I know programs that do this exist already, but I am having a ...