Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
1
vote
2answers
249 views
Binary tree data structure
I am learning about the binary tree data structure and implemented some basic functionality.
It was working great with module level functions until I realized that I need to keep track of the root ...
2
votes
2answers
44 views
Simple text game
I am new to coding and am working through Learn Python The Hard Way. I wrote a simple text game as instructed. The logic appears to be sound. I played through it and didn't run into any dead ends. ...
-1
votes
0answers
15 views
Flask, Python, MySQL - Query with parameters works locally on dev but not on the production server [on hold]
This issue has stumped me.
Locally I'm using Anaconda and running python 2.7. I serve my Flask app using run.py but connect to my actual database (hosted by dreamhost.com) even in the "dev" ...
1
vote
1answer
46 views
Check if a Binary Tree is full
Problem statement
Given a node check whether the sub-tree rooted at given node is full binary tree or not.
Definition
A full binary tree (sometimes proper binary tree or 2-tree) is a tree in ...
5
votes
1answer
58 views
Printing a staircase of text
So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them ...
1
vote
1answer
116 views
Binary tree from given Inorder and Preorder traversal
Below is code which builds a Binary Tree from given Inorder and Preorder lists.
...
2
votes
3answers
76 views
List comprehension method
I have developed some Python code which revolves around two custom classes - a 'Library' class (Lib) which contains a Python list of several objects based on a 'Cas' class. I've not posted the code ...
-2
votes
0answers
17 views
Tkinter in Python - Entry widget not displaying [closed]
I am trying to make an entry widget display beneath a Label using the .grid() function; however, it is simply not showing up. Here is my code:
...
4
votes
1answer
42 views
Find values in list which sum to a given value within tolerance
This is really a follow on from a question I asked earlier this year on Stack Overflow. I received a great answer to the following problem:
I'm trying to code up something simple and pythonic to ...
4
votes
2answers
101 views
Password generator script
What I was trying to do here was create a Python script that would generate passwords with 16 characters with uppercase and lowercase letters, and numbers. The generated password would then write ...
6
votes
3answers
279 views
Implementing xrange
I wanted to learn about Iterable and Iterators and hence thought about getting my hands dirty rather than reading theory and ...
3
votes
2answers
250 views
Project Euler #42 - Triangle Numbers
Here is the Euler problem referenced, it says:
The n\$^{th}\$ term of the sequence of triangle numbers is given by, t\$_n\$ =
½n(n+1); so the first ten triangle numbers are:
1, 3, 6, 10, ...
3
votes
2answers
45 views
Project Euler 62: cubic permutations, logic
Problem 62 of Project Euler goes
The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the
smallest cube which has ...
4
votes
1answer
63 views
Convert zip to gzip and upload to S3 bucket
My code accesses an FTP server, downloads a .zip file, pushes the file contents as .gz to an AWS S3 bucket.
...
7
votes
2answers
237 views
Generating 3 combinations in Python
I have been experimenting around with generating all the n-combinations of an array. This code quickly generates all \$\text{k-combinations}\$ of a given array. I am testing my own implementation ...
3
votes
2answers
70 views
Asking a user for the capital city of Peru, South America
Can this Python code be written in a more Pythonic way?
...
6
votes
2answers
89 views
Sudoku challenge driver program
For my planned Sudoku with Handicap challenge over at codegolf.SE, I need a driver program. I've decided to write it in Python, for learning purposes. Since I've got no Python experience, I thought I ...
1
vote
1answer
50 views
Timing Python functions in two ways
When reviewing questions here on Code Review SE, I sometimes find my self wanting to test different functions in order to do a performance review. However since I'm inherently lazy, I wonder what is ...
2
votes
4answers
237 views
Checking whether a list is sorted, ascending or descending
What is the best way to conditionally use an operator? All 3 methods seemed acceptable to me, and the last 2 better.
If you're curious: I've got a list which is unsorted, and many other lists which ...
4
votes
3answers
73 views
Multithreaded web scraper with proxy and user agent switching
I am trying to improve the performance of my scraper and plug up any possible security leaks (identifying information being revealed).
Ideally, I would like to achieve a performance of 10 pages per ...
3
votes
2answers
55 views
System backup on Linux - follow up
This is a follow-up to System backup on Linux. I've done a lot to my script since I asked my first question and I think I could improve a lot while doing this. The script still does the same, only a ...
4
votes
3answers
126 views
Kadane's Algorithm for 2D array with known boundaries
I asked this question first on StackOverflow but I didn't get an answer and was advised to try here too. So here we go.
I have implemented Kadane's algorithm for a 2D array in Python 2 with known ...
5
votes
1answer
77 views
Project Euler: #36 Binary and Base 10 Palindromes
Here is the Euler problem referenced, it says:
The decimal number, 585 = 1001001001\$_2\$ (binary), is palindromic in both
bases.
Find the sum of all numbers, less than one million, which ...
5
votes
3answers
896 views
Will multi-threading or other method make my program run faster?
I didn't use multi-threading so far as I didn't need to. But as far as I've read, implementing them will make my program slightly faster than it actually is.
...
9
votes
5answers
160 views
ASCII generator
Today I stumbled upon CodinGame, a site with programming challenges. I'll describe one of them.
ASCII art allows you to represent forms by using characters. To be precise, in our case, these forms ...
6
votes
3answers
92 views
Using an Equation from another Equation based on **kwargs
What my code does is that it takes input as to which function to use, and then plugs in the appropriate data in to the given function.
For example:
User input: force(1, density = 10.0, volume = ...
-1
votes
0answers
50 views
Returning the range of a number as a palindrome [migrated]
I like to do programming challenges in my free time to teach myself and keep fresh, this one I can't seem to optimize though and it's driving me insane.
The goal is essentially, "Given a number, ...
6
votes
1answer
110 views
System backup on Linux
I've written this Python script to make regular backups of a Linux server. It works pretty well except that the script sometimes backups files more than one time, which is pretty strange and I don't ...
4
votes
4answers
90 views
“Tractor” Python implementation
This is the Tractor problem from the Kattis problems archive.
Problem Statement
Bessie the Cow has stolen Farmer John’s tractor and is running wild on the coordinate plane! She, however, is a ...
3
votes
2answers
74 views
“Cut the sticks” Python implementation
Problem Statement
You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the ...
6
votes
3answers
943 views
“Angry Professor” Python implementation
Problem Statement
The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there ...
2
votes
2answers
52 views
Generating a PANDAS DataFrame of simulated coin tosses
It's taking my machine quite a long time to execute 1 billion (1st loop x 10, 2nd loop x 1000, 3rd loop x 100,000) instructions. Suggestions for performance enhancements? Sources of potential concern: ...
3
votes
4answers
53 views
Using Python to rename multiple csv files in Windows
I need to rename a large list of csv files that are generated from 3 different servers. The files are produced with a date stamp as the extension, which I need to move in each file name to retain the ...
4
votes
1answer
52 views
Project Euler # 22: Names scores
Problem 22, here, asks the following:
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical ...
6
votes
3answers
62 views
Python Turtle screen saver
Leon asked a question which got closed both here and at Stack Overflow, but I kind of liked the idea, so I implemented a working version of his code, which I now want reviewed.
With regards to Leon's ...
2
votes
2answers
41 views
Processing eBay category list for database import
Although I've been programming a fair while I'm learning Python and would like to know how I can make my code more "Pythonic".
I'm have a CSV file of eBay categories, containing the name and numeric ...
4
votes
1answer
41 views
Random Forest Code Optimization
I am new to Python. I have built a model with randomforest in python. But I think my code is not optimized. Please look into my code and suggest if I have deviated from best practices.
Overview about ...
-3
votes
1answer
46 views
Style guide on writing long Python code lines [closed]
When building a working example of a class, I ended up with the following statements which is violating the 80 character rule of PEP8. The code was inside a method inside a class.
Code excerpt is ...
6
votes
2answers
68 views
Project Euler #19: Counting Sundays in the 20th century using Pandas
Project Euler #19 asks:
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
I'm hoping I wasn't too off course from the spirit of the ...
4
votes
1answer
34 views
Using changeable column formatting to display table
When answering python tuition calculator v2, I got a little carried away, and started building a print_table() function which I don't like the resulting code for, ...
1
vote
1answer
29 views
Operating multiple columns of one pandas DataFrame using data from another
I have a DataFrame of data from a survey that was repeated over several years, asking people about their income and how much money they had in savings. For simplicity, let's pretend it looks like ...
2
votes
1answer
45 views
Weighted graph from a matrix (list-of-lists)
I created this code while solving the Euler Project problem 83.
In the 5 by 5 matrix below, the minimal path sum from the top left to
the bottom right, by moving left, right, up, and down, is ...
1
vote
2answers
42 views
“Time Conversion” Python implementation
Problem Statement
You are given time in AM/PM format. Convert this into a 24 hour format.
Note Midnight is \$ 12:00:00AM \$ or \$ 00:00:00 \$ and 12 Noon is \$ 12:00:00PM. \$
Input Format
...
2
votes
1answer
62 views
Binary search function
I have written this function to perform a binary search on an array, given begin/end indices and a value to look for in the supplied array:
...
6
votes
2answers
96 views
Python tuition calculator
I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best ...
2
votes
2answers
97 views
“Even Tree” Python implementation
Problem Statement
You are given a tree (a simple connected graph with no cycles). You have to remove as many edges from the tree as possible to obtain a forest with the condition that : Each ...
12
votes
3answers
283 views
Lexer for C- in Python
I am currently taking a compilers course where we are designing a compiler for C- (which is a subset of C). Our first step was the lexer and I have written that but I believe that it is not very ...
7
votes
4answers
1k views
1
vote
1answer
59 views
The largest odd number (follow-up code using nested functions)
Ask user to input 10 integers and then print the largest odd number that was entered. If no odd number was entered, print a message to that effect.
This is my follow-up code on feedback from Find the ...
1
vote
2answers
56 views
Project Euler #4 “Largest Palindrome product” in Python
Given
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product ...