Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
1
vote
0answers
10 views
Rotating list in python
This is a list class which allows users to "turn" the list while keeping track of the current position.
For efficiency, the list is not actually rotated on each rotation, but instead an offset keeps ...
-5
votes
0answers
21 views
Rock, Paper, Scissors game in python. How to correct my code? [on hold]
Why when the user enter an invalid input, the program didn't show that input is error even though i use if elif else statements? Here is my code.
...
8
votes
2answers
47 views
Finding words that rhyme
Preface
I was trying to review this question on the same topic, but in the end many points I wanted to make were excellently explained by @ferada so I felt that posting my code and explaining the ...
3
votes
1answer
24 views
Change password after being validated
I'm doing Python programming challenges and have come across one where the object of the challenge was to create a script to change passwords. The script must validate that the password contains, one ...
1
vote
1answer
34 views
Simple email validation script
I was doing a programming challenge and the object was to validate an email address, I wrote a simple little email validator and would like some input on how I can make it more efficient.
How it ...
3
votes
1answer
25 views
Round Two: File hash sum generator in Python
This is a follow-up review request to the first one for this same utility/file/script. The first review can be found here: Cross-platform file hash sum generator in Python
I'm back with the ...
2
votes
2answers
41 views
Python deep get
I'm implementing deep_get functionality to look inside arbitrarily nested Python 2.7 objects. Primarily for further logging.
This turned out to have surprising ...
4
votes
1answer
35 views
Python Dictionary Manipulation
I just finished working on a coding challenge for learning Python 2.7. Essentially, I'm a function that if it is fed a string such as:
...
2
votes
1answer
78 views
Drawing a planetary system in Pygame
I am new to programming and mostly self-taught by following a few MOOCs and doing little projects. I have reached the point where I am trying to develop more complicated programs (numerical models at ...
2
votes
1answer
21 views
Shortest code to generate a full mesh of elements
I am trying to find the shortest code that generates a full mesh of the elements fed into it in graphviz format
e.g. the full mesh of [0, 1, 2] is:
2 -> 0
2 -> 1
1 -> 0
I have the code below and I ...
-1
votes
1answer
45 views
Selenium Kijiji web scraper
I have this script working pretty well but I know that there must be many things that I could do better to make it more efficient.
...
3
votes
1answer
61 views
Sorting two lists
This sorts two lists (a, b) according to aand returns two sorted lists separately:
...
11
votes
6answers
2k views
6
votes
1answer
74 views
setup.py with data_files and __author__ parsing
All my projects have a fairly similar package layout:
...
5
votes
2answers
61 views
Cross-platform file hash sum generator in Python
I'm back for more community punishment review of my own scripts and code! This time, I'm looking for general code review of my approach to a Python way of getting one or more hash sums for a provided ...
1
vote
1answer
58 views
Print tree level by level including Empty node
Here is my code to print tree in a level by level way. It needs to print an empty node as well to keep tree structure like full binary tree for elegancy reasons.
I'm wondering if anything you think ...
1
vote
1answer
37 views
Check whether a given sequence can be rearranged using a stack
Working on a problem, for a given input sequence to a stack, check whether it could produce (using stack push/pop operations) the output sequence.
For example if input is ...
7
votes
4answers
1k views
Buy once and sell once for maximum profit
Suppose we have stock price history, and we are allowed to buy only once and sell only once. The problem is to find the maximum profit we can make. Here is my code that I tested for basic test cases. ...
11
votes
1answer
88 views
Rainfall - August 2016 Community Challenge (Hooray for graphs!)
A solution for the August 2016 Community Challenge (Rainfall).
I've intentionally left out error checking on the file formatting.
This seems like a very obvious graph problem to me - we want to ...
1
vote
1answer
93 views
Pokemon search engine
I am making a simple function to find and match any possibilities what Pokémon the user wants. This is accomplished by taking in the input (what the user thinks the Pokémon is named) and compare its ...
2
votes
3answers
55 views
Generating variables to be named, filled in and operated on the fly in Python
I am very new to Python and trying to refactor my code which is ripe for error.
Currently, I manually name a bunch of arrays:
...
4
votes
2answers
387 views
Memoization with factorial in Python
I wrote a Python module to learn about memoization, and I have some questions on what I did.
How pythonic is this?
Does it make a difference if I used a class attribute instead of a function ...
19
votes
4answers
311 views
When it rains, it pours - August 2016 Community Challenge
1. Introduction
This code is my attempt at solving the August 2016 Community Challenge. Coming from a city where it rains cats and dogs on a daily basis this challenge was right up my alley =)
2. ...
8
votes
1answer
46 views
A little text based adventure game
I'm writing a little text based adventure game, and wanted to know if there's anything I can do better thus far. It is not completed to don't get mad when it ends. I'm just curious as to better ways ...
1
vote
2answers
70 views
Another Python prime-listing algorithm
I wrote a small program in Python that finds primes (how original) up to some limit. I tried to produce very clean code, so I'd be vary grateful if you could point out any improvement I could do to ...
3
votes
2answers
75 views
Power flow analysis using the PSS/E simulation tool
The intro is a bit long. If you're not interested, then please read the update, and have a look at the specific parts I'm highlighting.
I'm very interested in any improvements, but you can assume ...
2
votes
2answers
95 views
Find if a part of the integer from another integer is divisible by 7?
The question states:
Given an integer A, and two indices Li, Ri. Find if the number from A which is bounded by the two indices is divisible by 7?
For example if A = 357753
indices Li = 3, ...
0
votes
2answers
96 views
Google Foobar Challenge: Spy Snippets in Python [closed]
I am getting all the answers correct. But still the solution is not accepted as only 4/5 tests cases are passed.
I have not posted the whole problem statement but the problem is similar to this.
I ...
3
votes
1answer
36 views
Emulating super() in Python 3.x using Python 2.7
Depending on the name of the first argument, self.__sup or cls.__sup behaves like super() in ...
5
votes
1answer
69 views
Apriori algorithm in Python 2
This takes in a dataset, the minimum support and the minimum confidence values as its options, and returns the association rules.
I'm looking for pointers towards better optimization, documentation ...
4
votes
1answer
72 views
Extracting time duration in the session from 30 million rows
I am looking for making my code faster. I am working on yoochoose recsys 2015 dataset.. and trying to perform some transformations.. [recsys2015], it has got 30 million plus rows of data. The goal of ...
1
vote
1answer
43 views
LRU cache in Python
Here is my simple code for LRU cache in Python 2.7. Appreciate if anyone could review for logic correctness and also potential performance improvements.
A confusion want to ask for advice is, I am ...
3
votes
0answers
27 views
KNN pipeline w/ cross_validation_scores
Using the wine quality dataset, I'm attempting to perform a simple KNN classification (w/ a scaler, and the classifier in a pipeline). It works, but I've never used ...
5
votes
3answers
415 views
Digital root computation with benchmarking
I've read this question about computing the digital root of some integer, and wondered how it would look like in Python.
As a reminder,
"If you take the digits of any number and add them together,...
2
votes
0answers
37 views
7
votes
3answers
98 views
How to decrease memory usage in codeeval Road Trip challenge
I'm solving easy CodeEval challenges in Python 2.7. Usually my solutions use around 256 bytes of memory according to CodeEval. With Road Trip however while time used is still low (30-40ms), memory is >...
7
votes
2answers
118 views
Program to find magic square of squares
I have a program which finds, well, a magic square of squares. The problem is, it's quite slow - it processes around 50 numbers in half a second when the number range is above 40,000.
Is there any ...
4
votes
2answers
109 views
Print tree in a zigzag manner
I want to print a tree in a zigzag manner level-by-level. I'm wondering if there are any logic issues in my code and any further performance improvement ideas by using a smarter algorithm ...
14
votes
2answers
3k views
O PC, why are you so slow?
In order to test some software I've written, I need to write values to a test harness with OLE for Process Control (OPC). The problem is, for a larger range of values I'm generating points for (say ...
3
votes
1answer
73 views
Calculate working minutes between two timestamps
I've created a function to calculate the working minutes between two timestamps.
I class working minutes as those between 9am - 5pm and not on weekends or national holidays.
The holidays are those ...
11
votes
2answers
115 views
Python Hash-Cracker
This is my first actual python tool I've written and I'm certainly happy with the way it works, but I'm sure there's better ways to do things in the code. Any ideas on how to speed it up would also be ...
5
votes
1answer
31 views
Princeton KMP implementation
I implemented a Python version of KMP followed by Princeton Prof Robert Sedgewick's discussion.
However, I got a Time Limit Exceeds error. Per leetcode's explanation, TLE indicates that the solution ...
5
votes
1answer
71 views
Generalized Project Euler 2: A sledgehammer to crack a nut
The task at hand
I have previously asked about how optimizing Project Euler 1. See Generalized Project Euler 1: A sledgehammer to crack a nut. In this question I wanted to explore the next problem: ...
4
votes
1answer
66 views
Buffer for TCP data
For an assignment (not school), I was supposed to make a "web browser" using Scapy.
While storing the response, I initially thought of
...
11
votes
3answers
2k views
Stone, Paper, Scissors in Python
Recently I started programming with python.
Today I was trying to make a stone, paper, scissor game. After so scratching my head long time, finally I got a working code.
...
3
votes
2answers
91 views
'Broken Record' Coding Challenge
I was asked to complete a coding challenge for an interview. The challenge being to write a test function to check whether or not a string was a broken record. A <...
2
votes
2answers
67 views
SPOJ ADDREV challenge - Adding reversed numbers
I'm a beginner Python (2.7) programmer, and I've just started solving basic problems on SPOJ. I correctly solved the ADDREV problem (http://www.spoj.com/problems/ADDREV/), however my code takes 0.06s ...
3
votes
1answer
62 views
A class to create and modify SQLite3 databases with a terminal
I would like feedback on the class I've written. The purpose is to dynamically create and interact with SQLite3 databases, accepting lists of complete or incomplete statements.
...
7
votes
1answer
40 views
Python App that parses file for lines that match a format
I recently wrote some code that was dinged on not having well defined tests and poor modularity. Was hoping someone could review my code and give me pointers on how to create more well-defined tests (...
4
votes
2answers
57 views
Implementation of a queue for digicode-like system
What it is about
I created an application where you need to push invisible buttons in a certain order to unlock the advanced mode. To handle this, I wanted to use a queue (FIFO) of my own, adapted to ...