Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
2
votes
1answer
65 views
Function to rebalance portfolio
I wrote a small code in Python to conduct a backtest. My 'rebalance' function is very slow and I would like to improve it. I need to profile it but I would welcome any opinion on how to refactor my ...
10
votes
1answer
61 views
Racetrack plotter
My Racetrack is just that. A Racetrack. You can't race it (yet) because I had trouble with collision detection, but I wanted to share it anyway.
It creates a base polygon by using ...
5
votes
3answers
44 views
Join strings with different delimiters and some possibly empty strings
I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
9
votes
5answers
1k views
0
votes
0answers
39 views
Adding multiple elements to list in dictionary [on hold]
So I made this method to set parameters from a text file:
...
5
votes
1answer
47 views
Hangman with ASCII
I have just made a game called Hangman. I have added some stuff which people don't normally use, like cheat-code/s, time.sleep().
How can I improve this, in both ...
-1
votes
0answers
44 views
8 puzzle using breadth first search [on hold]
I'm trying to do 8-puzzle using pycharm, I will first generate a 3x3 list and then shuffle it to get the initial board state example:
[1 , 2 , 3 ]
[4 , 5 , 6 ]
[7 , 8 , 9 ]
then I'll do some ...
6
votes
1answer
64 views
Python snake game
If anyone has the patience to take a look at my first python snake game, I'd be very grateful for any feedback. I am fairly new to programming and Python, but am looking to improve so any constructive ...
3
votes
2answers
46 views
Get all followers and friends of a Twitter user
I'm trying to find my bug or any potential bottleneck that cause my program to be really slow. The script is to get all the followers and friends and save that in MongoDB.
...
3
votes
2answers
51 views
Dataset and frequency list generation by looping over files
I have been told that it would be wise to split up my code into semantically useful blocks. I tried the following but I need feedback.
What I already did:
As you can see I create two .csv files, so ...
7
votes
2answers
85 views
'Mini Twitter' in Python 3
I've written a 'Mini Twitter' (that's what I've called it) in Python. It includes a text-based login screen and user panel where you can create Tweets, and change your username and password.
Users' ...
2
votes
1answer
33 views
Process PowerPoint XML
I run a tiny open source project to help create speech aids for disabled people (the github is here).
One of the things that is useful is for people to design speech setups in Powerpoint, and then ...
1
vote
0answers
28 views
Item purchasing using urllib
I have this function that gets an item passed from another function, together with the subtotal and the fee of the item. The function has to act as fast as possible, as other people also want the ...
9
votes
5answers
751 views
Generating a password to save to a .txt file
Here is my basic password generator which saves your password to a .txt file which you can choose the name of etc.
...
3
votes
2answers
39 views
Test if a network is online by using urllib2
My concerns:
Is the code pythonic
Is the code practical
I tend on expanding the usefulness of this script, if you don't think it's stupid idea. One thing I will implement is command-line arguments ...
1
vote
1answer
53 views
Bot that selects web reviews based on spreadsheet entries
In my program, I prompt the user to enter a range of cities (in a spreadsheet), and then a range of review scores, and then make some decisions based on what the user has entered. Since the handling ...
5
votes
1answer
62 views
Avoiding code repetition while handling exceptions
For my application, I need to use two slightly different algorithms for persisting an entity:
...
3
votes
2answers
121 views
+100
Generating frequency tables based on CSV dataset
I am working on a project which crunches plain text files (.lst).
The name of the file names (fileName) are important because ...
5
votes
1answer
63 views
Builder - A 2D Minecraft clone
I was poking around on my Raspberry Pi that I hadn't turned on or used in a while, and I stumbled upon this Python script that I wrote ~1.5 years ago, and I was intrigued.
Essentially, it's a 2D ...
0
votes
1answer
38 views
Looking within a directory for a file
I have written this code to build a list by looking inside directory within deep to the level it finds a audio file and then move to the next level or next folder.
Can there be a more efficient way ...
4
votes
1answer
102 views
Simple hotel reservation system
This is a reservations software for hotel and restaurant management, allowing you to add and delete rooms, show available rooms, keep track of reservations etc. I am looking to trim my code a bit and ...
6
votes
3answers
633 views
Chess game in Python
I have programmed for 2 months, and I began writing a Chess game. I am a beginner programmer in Python, so please assess my code.
...
2
votes
0answers
46 views
Jinja template with Flask
I have this code querying for some objects from my database with Flask-SQLAlchemy:
areas = Area.query.all()
subareas = Subarea.query.all()
And then I use it on ...
2
votes
1answer
29 views
5
votes
1answer
39 views
Recursive Fibonacci generator
I decided to write a function that would generate an index of the Fibonacci sequence making use of Python's mutable default parameter. It's inspired by a question I answered on Stack Overflow where ...
6
votes
1answer
46 views
ANSI colors cross platform
I am trying to write for both NT and POSIX (my two usual platforms) and have come up with the code below. The clrs code I refer to is apparently from blender build ...
2
votes
2answers
45 views
URL pattern matching
The whole process mainly depends on the ProcessFile() function:
I get all the credentials and details from a JSON file.
Initially I get data from the db: two IDs ...
4
votes
1answer
52 views
Project Euler 91 (via HackerRank): Right triangles with integer coordinates
This is my code to solve HackerRank's version of Project Euler Problem 91: on an N × N grid, find the number of possible right triangles where one vertex is (0, 0) and the other two vertices are ...
1
vote
0answers
22 views
Changing attributes in Django Objects outside of iteration
I'm adding three attributes to a Django QuerySet that represents a hierarchical tree structure:
a display_name which is added to all objects
the id of the ...
3
votes
0answers
29 views
2D disease problem modeling [closed]
I'm modeling a disease problem where each individual in a 2D landscape has a transmissibility described by a (radial basis) kernel function. My goal is to convolve the kernel with the population ...
-1
votes
0answers
10 views
How to combine these 2 processes into one [closed]
i'm extremely new and learning via self taught method.
essentially forcing myself to use python / powershell when capable.
This creates a new file but omits any line that contains text i specify in ...
7
votes
3answers
364 views
n number of x on the y
Everyone knows "99 bottles of beer on the wall".
Mat's Mug made a comment about mugs on the wall in The 2nd Monitor and I realized I never wrote a "beer on the wall" program. But that seemed way too ...
8
votes
3answers
656 views
Computer guesses the user's number
After the feedback for my last script, I realized I should be using functions and trying to adhere to the style guide. I tried to do that here, though still very beginner.
The rounding in Python ...
3
votes
3answers
201 views
Unit Converter in Python
I am new to programming and I am trying to make a simple unit converter in python. I want to convert units within the metric system and metric to imperial and vice-versa. I have started with this code ...
1
vote
1answer
33 views
Generic plotting wrapper (around matplotlib)
I am experimenting with making my own re-usable libraries. Therefore, I decided to start with some of the plots that I generally use during development/debugging to check what is actually inside my ...
4
votes
1answer
116 views
Binary search implementation [on hold]
Is there a better way to implement a binary search than I am in my code? My function is taking two two lists - first_booth_voters and ...
2
votes
1answer
27 views
CSV parsing program that creates distinct header rows with transaction rows underneath
My code reads in the data using DictReader, then creates a header row that contains my composite key (PEOPLE_ID, DON_DATE), and then adds various values that are ...
3
votes
2answers
82 views
Duplicate the previous input if zero or not a number
I have the following code which duplicates the previous input if any entry is less than zero or NaN, except the first row of a matrix.
Is there any other efficient way to do this without using ...
0
votes
0answers
24 views
Simple distributed lock manager server based on zmq
I wrote a simple server to distribute locks on a network. It is used in a multi-server environment with a shared home directory to secure non-multiprocessing safe file writing (...
1
vote
0answers
51 views
Depth First Search for percolation to find clusters in Go game
I have some questions about Depth First Search and whether I implemented it correctly. Below is a more thorough discussion. The graph in question is a randomly colored square grid (I use 3 colors). ...
5
votes
1answer
62 views
Parse OpenFoam files in Python
I'm writing a Python parser for OpenFoam mesh files. When the mesh is big, I face performance issues.
Here is the format of the file describing the points:
...
2
votes
2answers
47 views
Root-finding by iterated bisection
Both of the following code give the same result. But I'm not sure where should I put the raise statement.
...
4
votes
1answer
83 views
HackerEarth Challenge Find Maximum Taste of Fruits
Problem Statement:
Samu had got N fruits. Sweetness of ith fruit is given by A[i]. Now
she wants to eat all the fruits , in such a way that total taste is
maximised.
Total Taste is ...
7
votes
2answers
45 views
12
votes
2answers
127 views
Mengenlehreuhr in Python
Telling the time based on the "set theory principle", the Mengenlehreuhr consists of 24 lights which are divided into one circular blinking yellow light on top to denote the seconds, two top ...
2
votes
0answers
27 views
Elo Rating Tracking Applet
I have a little applet that I wrote in Python and Tkinter, and I was wondering what a good way would be to make it public, or open source or whatever.
I think it's quite fun. You can add players, ...
6
votes
3answers
67 views
ChessMetric - Topcoder Challenge
My solution for the topcoder ChessMetric challenge seems really slow. I feel like there should be a better way, but I'm not sure.
Challenge Description
Suppose you had an n by n chess board ...
3
votes
1answer
26 views
Complex sorting of nested data
I am retrieving data from Postgres (jsonb type) and I need to return an OrderedDict that has a predictable order for human and machine consumption. There are some ...
5
votes
3answers
86 views
Numerical Python code to generate artificial data from a time series process
I'm writing code to generate artificial data from a bivariate time series process, i.e. a vector autoregression. This is my first foray into numerical Python, and it seemed like a good place to start.
...
4
votes
1answer
38 views
AvoidRoads - TopCoder Challenge
I'm learning Dynamic Programming, following the topcoder guide. I just solved the AvoidRoads challenge. It passes all the test cases, but I don't have much experience, so I don't know if it's good.
...