Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
4
votes
1answer
45 views
Random MP3 Selector and Player
So, I am either a glutton for punishment, or I have no life, but I wrote a script to answer a question over on Ask Ubuntu as a solution for selecting a random MP3 file in a given directory, and ...
0
votes
0answers
15 views
Cropping faces from images in a directory
I am using the below code for cropping faces from images in a directory
...
1
vote
0answers
24 views
Protocol implementation, TCP, sending images through sockets (sockets, python)
I would like to ask about your opinion about my code. The idea is simple: I designed my own protocol, where client asks server about the image, and the server sends the image, following the below ...
-4
votes
0answers
12 views
8
votes
1answer
46 views
Implementing my own network protocol using TCP, sending images through sockets (sockets, python)
I would like to ask about your opinion about my code. The idea is simple: I designed my own protocol, where client asks server about the image, and the server sends the image, following the below ...
3
votes
0answers
24 views
Quick select - shuffle to make sorting faster
I'm trying to use shuffle to improve worse case scenario of quick select (e.g. every time, selected pivot value is the largest, so each iteration, only one elements could be removed from judgement).
...
1
vote
3answers
47 views
Two ways to randomly shuffle cards
Here are two implementations I wrote to randomly shuffle cards.
The first method (shuffle) selects a random card, then swaps it to the front.
The second method (<...
-5
votes
0answers
26 views
Exporting to excel file [on hold]
The following code should combine the csv files in the folder and return an xlsx file. But the excel file returned is blank. Please help in correcting the code.
...
-3
votes
0answers
24 views
How to read PDF in python 2.7? [on hold]
I am using the code below to read a few pdf files in a folder.
...
6
votes
1answer
48 views
Expanding url from shortened url obtained from tweet
I have a twitter data set. I have extracted all the expanded urls from the json and now am trying to resolve the shortened ones. Also, I need to check which urls are still working and only keep those.
...
6
votes
0answers
48 views
13
votes
4answers
654 views
Reading a DHT11 to a file
Disclaimer: not a Pythonista, first actual Python programme written right here.
I'm reading a DHT11 sensor from GPIO pin 4 on my Raspberry Pi (thanks Thomas Ward for sending the RPi to me), and I ...
5
votes
1answer
56 views
Python with alternative keywords - follow-up
Original post here. I've taken @ThomasWard's advice, and also added a couple other things.
...
3
votes
2answers
52 views
Get value from dictionary given a list of nested keys
I would like to get a deeply-nested value, for example {"a":{"b":{"c":"myValue"}} by providing the keys to traverse. I tried chaining together .get() but that didn'...
11
votes
1answer
143 views
Python with alternative keywords
A while ago, a user on Programming Puzzles and Code Golf had an idea:
How about a language where all of the core commands are PPCG usernames? -- Helka Homba
A list was made of username/(keyword|...
3
votes
1answer
99 views
Implementing heap in Python
This is basically a straightforward heap implementation. I am just moving from C to Python and I wanted to make sure that I follow Python's best practices in general. This heap is supposed to support ...
8
votes
2answers
134 views
Create two vehicles, move them on a grid based on user input
I have a grid and a class Vehicle, which will have starting point(X, Y on the grid) and direction(one of N,E,S,W) taken from user and there will be commands, ...
5
votes
0answers
27 views
Find the nearest point of a given set of points (part 2)
This is a continued discussion from here, and I use new a approach (bounding box/or envelop algorithm) to improve the algorithm efficiency. Any code bugs, algorithm time complexity improvement or ...
6
votes
0answers
41 views
Sudoku solver recursive solution
Here is my code in Python 2.7 for a Sudoku resolver. Any advice on performance improvement, code bugs or general code style advice is appreciated.
My major idea is:
Using method generate some random ...
5
votes
1answer
83 views
Counting the number of elements in a sorted array
Suppose I have a sorted array, and each element may appear multiple times.
To make it simple, here is an example:
...
6
votes
1answer
64 views
Find the nearest point of a given set of points
Suppose there are a set of given points (represented by x and y two dimensional coordinates), and for any given point A, I want ...
3
votes
2answers
53 views
Finding an equilibrium of an index of an array
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. P is an index of an ...
7
votes
1answer
206 views
Stock statement generator in Python
I applied to a startup recently, as a coding exercise they asked me to produce the output below with the given input, specifically making it easy to understand, extend, and without performing any ...
7
votes
2answers
148 views
Optimizing the speed of a web scraper
I have just written this code to scrape some data from a website. In its current state it works fine, however, going by my tests on the script, I discovered that with the amount of data I am ...
8
votes
6answers
865 views
3
votes
0answers
80 views
Simple directory and file serialization protocol for Python 2 and 3
The first edition of this code was written back when Python 2 had not yet been deprecated in favor of Python 3. The difference between strings and bytes were not very clear back then. Also, PEP8 ...
3
votes
2answers
63 views
Estimating Pi with random darts on dartboard - high complexity issues
I've been trying to write nice snippet of code to simulate pi estimation by randomly throwing darts on a dartboard. While running the following code on high but reasonable numbers my mac doesn't plot. ...
7
votes
1answer
123 views
Raster processing for climate change model
I am working on a project on how climate change may affect the development of spruce budworm larvae throughout each year (historical and projected) using different climate change models and emission ...
6
votes
0answers
83 views
Extended stable marriage challenge
I've written a solution for the stable marriage problem in the case that the number of men is not equal to the number of women. My problem is not that I can't prove my code is right. The problem is I ...
1
vote
0answers
25 views
Shortest path while removing a unpassable node - Google Foobar [closed]
This is a follow up to this post, wherein a BFS algorithm is needed in order to find the shortest path between two points, which are [0,0] and ...
6
votes
2answers
67 views
Prefix search by trie tree
I'm working on the prefix search problem:
Given a set of words, for example words = ['a', 'apple', 'angle', 'angel', 'bat', 'bats'], for any given prefix, find ...
7
votes
1answer
43 views
LXC Bootstrap - A wrapper script around lxc utility scripts to create and set up an LXC container based on settings
So some background here.
I recently discovered the ease of LXC containers on Ubuntu. I've been building some 'test' containers locally for testing things I develop on Ubuntu, but the evil thing is ...
3
votes
1answer
74 views
Dynamic programming solution for cross river algorithm (part 2)
I'm working on the cross river problem (previous post here). Any advice on performance improvement in terms of algorithm time complexity, code bugs or code style advice is appreciated.
More ...
5
votes
1answer
85 views
Dynamic programming solution for cross river algorithm
Working on below cross river problem, and post my code in Python 2.7 using dynamic programming. Any advice on performance improvement in terms of algorithm time complexity, code bugs or code style ...
2
votes
1answer
64 views
Minimize max distance of Gas Station
I'm working on this problem, and any advice on performance improvement, bugs or code style issues are appreciated.
Problem
Description
There are N gas stations on a straight, M kilo-meters ...
6
votes
0answers
48 views
Using range minimal query for lowest common ancestor (LCA) — part 2
Here is my code to use range minimal query to resolve the LCA problem. I applied comments from here.
Any advice on code bugs, performance improvement in terms of algorithm time complexity, code style ...
2
votes
2answers
75 views
Balanced smileys check algorithm (part 4)
This is a follow-up for here, for bug fixes and applied advice.
Problem
Your friend John uses a lot of emoticons when you talk to him on
Messenger. In addition to being a person who likes to ...
7
votes
1answer
64 views
Python hash verification tool
I wanted to better understand regular expressions, however, just learning regular expressions would be extremely boring. So I created a simple little program that will verify a hash by the length and ...
5
votes
1answer
49 views
Balanced smileys check algorithm (part 3)
This is a follow-up for here, for bug fixes and applied advice.
Problem
Your friend John uses a lot of emoticons when you talk to him on
Messenger. In addition to being a person who likes to ...
3
votes
1answer
41 views
Merging vertical lines that coincide
I have a list of lines and I need to merge those who are similar (for example my machine vision script will return 3 small vertical line instead of one long vertical line).
I came up with this.
I'm ...
2
votes
2answers
106 views
Balanced smileys check algorithm (part 2)
This is a follow-up for here.
Problem
Your friend John uses a lot of emoticons when you talk to him on
Messenger. In addition to being a person who likes to express himself
through ...
0
votes
0answers
39 views
4-sum algorithm optimization
I'm trying to map this problem into a 4-sum problem, and I find the time complexity is always \$O(n^3)\$. Is there a way to optimize time complexity, with constant additional space complexity \$O(1)\$?...
3
votes
1answer
41 views
Convert BeautifulSoup4 HTML Table to a list of lists, iterating over each Tag elements
I am trying to convert a BeautifulSoup4 HTML Table to a list of lists, iterating over each Tag elements and handling them accordingly.
I have an implementation of this that works at a surface level ...
3
votes
1answer
106 views
Guess number with lower or higher hints
Problem statement
Two players - Alice and Bob. Alice needs to guess a number \$n\$, from
range \$[1, N]\$, \$N \le 200\$
In \$i\$th turn, Alice guesses a number \$i\$
Bob chooses to ...
2
votes
0answers
25 views
First basic API using Flask with authentication
I've created my first basic API using Flask, that has the ability to create new tasks, delete tasks, update tasks, handles error pages, and has authentication required.
What I would like to know is ...
-1
votes
2answers
60 views
7
votes
0answers
61 views
Check “five in a row” for a 15x15 chess board (part 2)
This is a follow-up from here. I have a further optimization for space complexity by store only direction status data for one row for each directions (refer to variable ...
1
vote
0answers
28 views
Quick select the kth smallest value (part 2)
Here is my code for quick select and a continued discussion from (Quick select the kth smallest value). Since it is new code, I made a new post.
Any performance improvement in terms of algorithm time ...
3
votes
1answer
35 views
Circle check algorithm optimization for directed graph
Here is my two versions of code to check if there is a circle for a directed graph. Any advice on performance improvements in terms of algorithm time complexity, code bugs or code style are highly ...
1
vote
0answers
52 views
Function Prototype Parser for objdump --stabs
This is the first "non-tutorial" that I've written in Python. Please critique me on both form/style and function (efficiency matters).
This prints the function prototypes from an ELF compiled with ...