Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
2
votes
0answers
8 views
Vectorized numpy version of arange with multiple start stop
Given a single start and stop, numpy.arange is a good solution for building a NumPy array of evenly spaced values. However, given an array of start and an array of ...
1
vote
1answer
19 views
2
votes
1answer
17 views
Decision tree for binary classification
I want to become a good Python programmer and so I'd like to know what in my code practices I can improve. Overall I feel like a pretty solid programmer but writing this code felt very "Java" so I am ...
2
votes
0answers
20 views
Triangle rasterization using a scanline algorithm for numpy array indexing
I need to access those elements of a large numpy array that lie in a small triangular area. The brute force solutions of using ...
3
votes
0answers
22 views
Modified Taylor diagrams
There is a type of diagram summarizing how well predictions from numerical models fit expectations; one obvious use case is comparing machine-learning regression models. Modified Taylor diagrams are ...
2
votes
2answers
44 views
Frequency distribution of words and phrases
I need to find a way how to create a frequency distribution out of multilple text files. In fact I am asked to check the number of times a word or a phrase occurs in a txt file. The code should check ...
8
votes
2answers
97 views
Predator Prey Simulation
Below is a simple random walk predator prey simulation that is optimized to the best of my abilities. I would love to hear about any improvements that can made.
...
4
votes
2answers
107 views
String replace templating utility
I am new to Python and I am writing my first utility as a way to learn about strings, files, etc. I am writing a simple utility using string replacement to batch output HTML files. The program takes ...
3
votes
3answers
110 views
Optimization of stack frame usage with recursion
For the given below exercise:
Here is one method to check if a number is prime:
...
-1
votes
0answers
11 views
batch rename files recursively to user entered depth of sub folders
Please review the code I am looking for improvement in terms of performance and testability.
...
4
votes
3answers
124 views
Stack Implementation in Python
I have written a simple stack implementation and would like some feedback as to what I could improve in my code and coding practices.
...
3
votes
1answer
18 views
OVH email manager script using docopt
This is what I coded to realize a command line program to make it easier to manage emails on ovh shared hostings. It's working ok but it seems ugly.
I'm a beginner with Python and ...
3
votes
1answer
37 views
Square spiral matrix
I've written a Python script to generate the closest square spiral matrix to a given number.
I'm new to code reviews as a practice, and I'm interested in ways to improve. Please suggest improvements ...
3
votes
1answer
30 views
Factors sieve optimization
I have written a more powerful version of the sieve of Eratosthenes: this sieve returns the number of factors of all the numbers below the limit. Sadly the running ...
3
votes
2answers
48 views
Function returning higher order function
For the below given exercise:
Define a function cycle which takes in three functions as arguments: f1, f2, f3. cycle will then return another function. The returned fuction should take in an ...
7
votes
2answers
71 views
“Lost in the Woods” text-based game
This is my first Python text-based game. Let me know if there is something I should improve on or fix in the way that my code is written because I feel that I am being very redundant in my code, but ...
0
votes
0answers
35 views
Type checking at runtime
For the below given exercise question:
Many procedures require a certain type of argument. For example, many arithmetic procedures only work if given numeric arguments. If given a non-number, an ...
1
vote
1answer
20 views
NumPy eliminate double loop
How can I vectorize this code snippet and eliminate this double loop? Even with "only" 1001 elements in a this takes almost 30s.
...
1
vote
1answer
12 views
Implementing a Trie in Python using lists alone
I've been working on implementing a Trie in Python for educational purposes. I tried implementing one using dictionaries and I was successful; find below my attempt at implementing a trie using lists ...
4
votes
2answers
266 views
Amazon web scraper
I am trying to improve my programming and programming design skills (poor at the moment). I created a small Amazon scraper program. It is a working program. I would be very grateful if you could ...
1
vote
0answers
16 views
Conway's Game of Life in Python3 (follow-up)
I asked for a review of my code, and after making the suggested changes I feel that now the OOP version is clearer in its meaning and overall the code looks cleaner.
...
2
votes
2answers
58 views
Web-scraper for a larger program
I have a web scraper that I use in a part of a larger program. However, I feel like I semi-repeat my code a lot and take up a lot of room. Is there any way I can condense this code?
...
2
votes
1answer
21 views
Selecting a subset of the data from a list
I have a list called all_dates which contains timestamps for a number of days (hourly). I wanted to select each day (i.e every 24 items in the list) and pass it to ...
2
votes
1answer
21 views
CSV manipulation with Python
I've prepared a script to manipulate csv files in Windows that simply adds quotes as requested.
The script creates a backup of the original files and overwrite the wrong originals in its same folder.
...
5
votes
1answer
293 views
Conway's Game of Life in Python3
I've implemented Game of Life in Python for a programming problem, in two different versions: one is a simple script and the other uses a class with a dictionary to initialize the various parameters.
...
3
votes
2answers
296 views
Rotating an NxN matrix
I came up with the following solution for rotating an NxN matrix 90 degrees clockwise, to solve this CodeEval challenge:
Input
The first argument is a file that contains 2D N×N matrices ...
3
votes
2answers
48 views
Use git to get SHA-1 of repo
I've created the function below to get the SHA-1 of the repository used by my CI server. The hash is then used to update the pass/fail status of the commit on GitHub.
I'm a python amateur. What ...
8
votes
3answers
334 views
Soundcloud to CSV File
This program connects to Soundcloud and turns the supplied username into a CSV file with the user's like list. The code accomplishes this although it looks rather messy and was wondering what I could ...
2
votes
1answer
52 views
Simple sum calculator
I'm looking to optimize a simple sum calculator used in Project Euler+. The premise is simple: Find the sum of all the numbers divisible by 3 or 5 under X.
At first I did it like so:
...
3
votes
1answer
34 views
Alerting users with a pop-up window
I'm relatively new at programming in general including Python. But I've tried to create a program in Python that alerts users through a pop up window to perform an action every 2 hours.
...
-2
votes
0answers
30 views
3
votes
1answer
39 views
Long running Python “server status” collector
I wrote a small program that collects the server status, caches it for a certain amount of seconds, and then sends that to a mothership server. It's broken down into a few pieces, starting with ...
-3
votes
0answers
18 views
r spliting troubles [closed]
So I am trying to create a function in which the last word of a string is extracted. I know rfind is the method to use it, however i am having difficulty find how ...
0
votes
0answers
16 views
Building a Raspberry Pi network monitor. My code is not working [closed]
A little background on me, I have 2 weeks of experience bash scripting on Solaris from a class about 2 and a half years ago, no python experience what so ever till this past Friday. I am a windows ...
3
votes
1answer
49 views
Letter Combinations of a Phone Number
I was asked to code a solution in Python in 15 mins. Print all possible word combinations for a given phone number. Numbers 0 and 1 will not be part of the phone number, the numbers can be repeated, ...
0
votes
1answer
27 views
Networkx VS graph-tool
I'm working on graph mining, so I'm trying to find the best library to do that.
I've read in here that "graph-tool" is faster, so I tried the same program who count the duplicated graphs (I call them ...
4
votes
1answer
57 views
If a message is there, but you cannot see it, is it really there?
I have created a space encoder program, because it is fun to generate invisible messages. (This programme is not cryptographically secure, it is just for fun)
...
-1
votes
0answers
41 views
How can i make this code more efficient? [closed]
Problem: I have two lists. For the element at position i in each of these lists, I want to take the minimum of these elements, and then add them up and append the sum to a separate list. In the case ...
0
votes
0answers
15 views
Using global variables in Python unit tests [closed]
Here's a very simple test in nose
def simple_test():
x = 2 + 2
assert x == 4
Imagine x = 2 + 2 is setting up a test. ...
2
votes
0answers
71 views
Multipurpose command-line utility to manage a web application
I'm creating a command-line tool which is supposed to work on both Windows and Linux OS. It will be used to manage our application - start, stop, deploy etc.
We have it in bash scripts now (and it ...
-1
votes
1answer
39 views
Python IF statement without comparison operators [closed]
I know people on SO/SE are a bit butthurt that no one knows where to asks the questions, so I hope this thread somehow fits into this sub forum ;-)
If i have to check if a value in my django model is ...
3
votes
3answers
162 views
Find the index of the element with maximum absolute deviation
I just completed a Codility test. The question presented was pretty simple but I may have over thought it.
Question:
Find the element which has the highest absolute deviation from the mean. E.g. ...
2
votes
1answer
119 views
Dumping fields from Python objects
I am writing a small class that has one method: get_state. It is parameterless and returns a dictionary of all the names in self (look in its dict) that are not ...
0
votes
2answers
57 views
Using recursion to count nodes in a binary tree, test equality of linked lists, and find extrema of a linked list
I am working with a some small functions to test recursion. I am fairly new to Python and am wondering if there is a cleaner way to get the job done.
...
4
votes
1answer
40 views
Reading an Excel file and comparing the amino acid sequence of each data pair
Since I am fairly new to Python I was wondering whether anyone can help me by making the code more efficient. I know the output stinks; I will be using Pandas to make this a little nicer.
...
5
votes
4answers
257 views
Get letter grade using eval()
I understand that using eval is extremely dangerous as it can execute deadly commands as an input by the user.
I'm trying to write a code to get a letter grade from a number between 0 to 1. I was ...
0
votes
0answers
20 views
How do I perform a Caesar Cipher on elements of a list using list comprehension [closed]
I am very new to Python and have run into a road block. Is it possible to use list comprehension to perform a shift on each letter of a word in a list.?
I was wondering because I know that I am able ...
-1
votes
0answers
21 views
Am i not properly using multithread? [closed]
I have a program that uses selenium webdriver to scrape some pages. Then a gui which displays the amount of scraped items.
The simple gui has three simple components. A start button which calls the ...
2
votes
1answer
31 views
Scraping through product pages
I'm working through a scraping function where pages of results lead to product pages. I've added a default maximum number of results pages, and pages per set of results, to prevent a simple mistake ...
1
vote
3answers
53 views
Counting the frequency of letters in a string slices
While preparing a solution for the CodeChef - magic tricks, an easy question about counting the frequency of given character from the string slice, I came up with the following solution:
...