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

learn more… | top users | synonyms

3
votes
1answer
24 views

Optimizing a Tic-Tac-Toe AI

I built a Tic-Tac-Toe game in Python. The board is made of ASCII characters and it is the user versus an AI. The user chooses a number (1-9) and if the corresponding spot is open then either an 'X' or ...
0
votes
1answer
15 views

Fraction Class in Python

I decided to train myself in OOP with a simple perfect precision Fraction class. ...
4
votes
2answers
123 views

Return a random line from a file when user enters a specific text

I am a beginner trying to fetch a random line from a file and wondering if this code can be improved. Should I use try and catch in this case? Should I take a parameter for the function "quote"? How ...
2
votes
1answer
21 views

Uploading and downloading files with FTP

I'm learning Python and decided to rewrite my FTP tool from Perl to Python. The program is able to up/download files, change the directory and list the files of the current directory. Is there ...
1
vote
0answers
9 views

Universal nested get/set for trees in Python

Based on this source, I've made the following universal get / set function, to make it possible to work on OrderedDict trees for example. ...
1
vote
0answers
7 views

Optimizing a drawing a circular gradient in Python (aggdraw, PIL or SDL2)

I need to reduce the latency in creating a circular gradient of arbitrary radius that's then mapped to the current mouse position. Though the project uses OpenGL for video-card interaction, alas, ...
0
votes
1answer
53 views

“Data Abstraction” and “Abstract Data Type” for a rational number [on hold]

Below is implementation 1 of data abstraction for rational number using functional paradigm written in Python: ...
-4
votes
0answers
18 views

Error with line 13 in Python fizzbuzz program [on hold]

just wanting to know why my python Fizz Buzz program does not seem to be working, the problem seems to be line 13. Advice would be appreciated as a beginner, i cant seem to spot the problem. ...
0
votes
0answers
17 views

Object Oriented design - connection to multiple databases

I have a Python application which uses both SQLite and Postgresql. It has a connector class for each database: ...
1
vote
1answer
26 views

User input function keep looping until valid filename entered

The following function is basically asking the user to input a file name for a file that the calling program is going to do something with. If the user enters an invalid file name, I want the program ...
1
vote
1answer
17 views

Parsing specifically nested XML Tags

I've written a function that works however I'm sure there is a better way. I need to parse specific tags from an xml document (Microsoft Word docx document.xml). Here is the general structure of the ...
4
votes
0answers
39 views

Parsing > 30 GB file in least amount of time

My Goal: To efficiently move data from Amazon S3 to Amazon Redshift. Basically, I am moving all CSV files on my S3 to Redshift using the below code. I parse through part of the file, build a table ...
2
votes
1answer
120 views

Labeling alternating max/mins based on a user defined delta

Given a set of values (points on a graph) find all the max/min points such that there is no max is followed by a max (i.e. the max and min points alternate) there is some minimum amount of change ...
1
vote
0answers
24 views

Conference track management

I was learning my way on designing real world OOP problems and I was trying to solve this problem in the OOP way. The problem statement is as follows: ...
4
votes
1answer
38 views

Number-guessing game with simple GUI

This is my second program in Python. I am aware that globals are a bad idea, but that is what I have learned so far in my course. Right now the program is doing what it's supposed to do, my only ...
3
votes
1answer
64 views

Iterative equation solver in Python

In order to solve a equation where the left hand side appears under an integral on the right hand side: $$ B(p^2) = C\int_0^{p^2}f_1\left(B(q^2),q^2\right)\mathrm{d}q^2 + C\int_{p^2}^{\Lambda^2} ...
1
vote
0answers
11 views

CLI wrapper for Yakuake

I have a CLI wrapper for https://yakuake.kde.org/. Python 3.4.*. ...
3
votes
1answer
32 views

Spending a target sum, preferably split equally

I have a strange programming prompt. I managed to complete an algorithm to solve smaller test entries (which i'll post). One of my test cases has to complete a 200,000 int input and my algorithm isn't ...
1
vote
0answers
24 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
30 views

Stripping leading tab of each line from a file

I've got this Python code: ...
2
votes
1answer
20 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 ...
3
votes
1answer
42 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 ...
4
votes
0answers
36 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
51 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
113 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
3answers
133 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
120 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
12 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
133 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
23 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
41 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
32 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
50 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
76 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
37 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
22 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
13 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
274 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
17 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
63 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
25 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
24 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
294 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
298 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 ...
4
votes
2answers
57 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 ...
1
vote
2answers
15 views

Insert elements into a list

I am a newbie trying to insert elements after the n:th element in the list. Any shorter/smarter ways? ...
8
votes
3answers
335 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
53 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: ...
4
votes
1answer
37 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