Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

3
votes
1answer
39 views

Simple RSS to HTML converter

My Concerns Is this code pythonic? Is this code easy to read? is this code stable? is this code missing something? ...
8
votes
3answers
581 views

Dictionary of dictionary - Get 2nd keys

I have a dictionary of dictionary such as d below, and I would like to get the list of all keys but not on the first level (i.e. ...
4
votes
1answer
37 views

Using NumPy to scale data in 2 out of 3 columns

The below code takes a csv containing age, weight, height and prints the betas determined through linear regression to an output csv. It runs for 10 iterations using a different alpha for each, and ...
1
vote
0answers
42 views

Using BFS to solve 8-puzzle game using Python 2

I'm trying to solve the 8-puzzle game using BFS, DFS and A* algorithms implemented using Python 2.7. For now, I have managed to solve a couple of test cases using BFS and I want to know how I can ...
2
votes
0answers
50 views

Unorthodox way of attaching a `property` to a class

I know I'm supposed to create properties like this: ...
8
votes
1answer
104 views

Black Jack Game in Python (Jupyter)

I am working on Jupyter Notebook and I am new to Python. I have created this BlackJack Game (This is my 2nd Project as I am Learning Python. See my 1st - Tic Tac Toe ...
6
votes
1answer
183 views

First time using Tkinter

This is my first time using Tkinter and really trying to get use to using classes in Python. I wonder if I'm using self entirely too much, but here is my code: ...
12
votes
3answers
293 views
+50

My images have secrets A.K.A. the making of aesthetic passwords

This is my implementation of a prng steganography tool written in Python. You can also find the code on GitHub. Steganography is the art of hiding messages in (images, videos or even audio) I've ...
2
votes
0answers
29 views

Algorithm for point distribution of traversal between 2 points on a line in time

Not sure if this is best SO forum to post at, please suggest/move to more appropriate place otherwise. A synopsis of the problem 1st: Given a scenario where we have messages with data that define a ...
4
votes
1answer
41 views

Aggregating text and deleting duplicates with pandas to consolidate a table for reporting

At work, I use software for analyzing administrative data and daily I generate a CSV that looks like: ...
-3
votes
0answers
30 views

Return especific sequence

The code is test passed, but to refactor? To pythonic code? I running in Python2. ...
3
votes
1answer
50 views

Implement a boto3 RDS generator in Python

Boto3 does not seem to implement a generator for RDS instances, instead offering a marker and pagination feature. This code does work for my use case and I have been using it for the entire day ...
7
votes
1answer
86 views

Tic Tac Toe in Python (Jupyter)

I am working on Jupyter Notebook and I am new to Python. I have created this tic tac toe game. ...
12
votes
4answers
1k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t ...
6
votes
0answers
93 views

Simple AR Tag classifier

I have been working on creating a simple AR Tag classifier, for detecting a simple AR Tag glyph. Spitting out an image that looks like this: With the red circle indicating the corner closest to the ...
2
votes
0answers
39 views

Remove songs from a playlist on a webpage using a text file and a dictionary [closed]

I am writing a Python program that will be called through a web page and will allow users to select which songs they want to remove from the site. I have a text file called playlist.txt that includes ...
6
votes
2answers
56 views

Recursive function and memorization to find minimum operations to transform n to 1

I'm a new, self-taught programmer working on the Google FooBar challenge. I've submitted my answer (code at bottom) and it was accepted, but I'd like suggestions on how to improve my solution. ...
19
votes
2answers
3k views

Password Checker in Python

Using Python 2.7.12 I wrote a simple little script, psk_validate.py, that prompts the user for a potential password and checks if it has upper and lower-case characters, numbers, special characters, ...
8
votes
1answer
98 views

Creating strings of desired length from a list of substrings

I have a method that generates strings from a list of substrings, and the desired length of all these strings is passed as an argument of the method. Here is my code: ...
3
votes
2answers
78 views

Random Password Generator based on user input

This is my second program written in python. It basically creates a password made up of numbers, capital and lower case letters with the option to include special characters and dashes. I created a ...
4
votes
1answer
37 views

Looping through multiple breadth first search test cases

I'm a new and self-taught Python programmer. I've been working my way through the Google FooBar challenges and wrote the following for the prepare_the_bunnies_escape challenge. I submitted the code ...
4
votes
2answers
48 views

Validation methods to ensure start and end date come after existing instances

We have a "Committee" class and I need to ensure that any new committee has start and end dates (don't know why they're CharFields instead of Dates or even Ints, but that's not my call) that are after ...
3
votes
1answer
63 views

Django REST Framework - PDF Generator

I created a new endpoint for an API (Django REST Framework) that generates a PDF from an HTML template. I follow the example from the plugin django-easy-pdf. It's working, but I would like to improve ...
8
votes
1answer
140 views

Kernel Convolution in Python 2.7

The code I wrote performs a mean blur on an image (I hardcoded it as zebra.jpg for testing purposes). My problem is that for an image of 39KB image it take minutes to perform, is there any way of ...
0
votes
0answers
22 views

matplotlib get_legend_handles_labels always return empty

I have a problem when adding elements to the same figure. The problem is with the legend. At each iteration I add elements and the corresponding legend. But I want the legend to include all the ...
0
votes
0answers
53 views

Code that extracts items from a list of websites and creates Tkinter text labels using their values

I have a chunk of code that I know is way too long for the rather simple output I get. It is simply creating a list of items found within a list of websites. It then assigns the text from each of ...
4
votes
1answer
79 views

Using Python to remove blank lines and comments in Assembly code

I made this little script to help a friend. He studies computer engineering and is doing a project where he has to make assembly files with comments and some formatting for presentation, but, as he is ...
1
vote
0answers
13 views

QtGui interface - improvements to structure

My code brings up a GUI interface, the user enters info: text that ends up in the resulting report, and dialog windows that select a file, be it data or a picture. I have been using this code ...
4
votes
1answer
55 views

Select value based on condition on dataframe

I have some data in data frame and would like to return a value based on specific conditions. It is highly time consuming. I tried three methods: Method 1: Without dataframe, this is the simple ...
4
votes
1answer
62 views

Creates a maze from file and enable user to go trough it with graphic display

I'm following the learnpythonthehardway.org book for learning Python. I recently made a one week projet and as I'm fairly new to coding program with POO and multiple files, I'd like to have someone ...
7
votes
2answers
441 views

Using python and beautifulsoup to iterate through a list of websites to find a particular string

I'm attempting to find companies who mention a particular service in on their homepage. To do this, I am iterating through a csv file with two columns - ID and URL. I'm using BeautifulSoup to get the ...
3
votes
1answer
58 views

Python CGI front-end for web service to perform machine translation

I am trying to optimize this python script that is used to process web requests for machine translation. The actual translation executable that is called is quite fast. Also, the perl scripts that are ...
3
votes
2answers
134 views
1
vote
2answers
55 views

Chain Responsibility Pattern to filtering messages

Is this a good implementation of a Chain Responsibility Pattern? This code attempts to filter a message received (for instance, in a chat application). ...
1
vote
0answers
33 views

extract partial of string if pattern found and return the value as list [closed]

I would like to write a function to parse a string based on the input. The following function works but is there a better way to do it? ...
1
vote
1answer
46 views

Drawing pixel to pixel

I'm drawing a pixel by pixel image with the following code: ...
1
vote
1answer
71 views

Bank account balance data structure design and code

I'm working on designing a bank account data structure and related operations (1. debit, 2. credit and 3. get balance difference). Debit means withdraw some money from an account, at a certain ...
5
votes
1answer
147 views

Game winning optimal strategy

Consider a row of n coins of values v1 . . . vn, where n is even. a player selects either the first or last coin from the row, removes it from the row permanently, and receives the value of the coin. ...
0
votes
1answer
51 views

Dijkstra's shortest path with max intermediate nodes limitation

Suppose want to calculate the shortest path from one node to all other nodes, with the restriction of intermediate nodes cannot be more than a given number. My major idea is, following how Dijkstra's ...
1
vote
1answer
67 views

Find index where left sum equals to right sum

Given an array, find if there is an index where left sum equals to right sum. My idea is calculate sum, and scan again to see if there is an index for which ...
1
vote
0answers
35 views

Blurring an image using matrices

Suppose there is a very big matrix and and a small window is moving on the matrix. The small window will move right and down, step by step (means each time move one step right, or move one step down). ...
3
votes
3answers
94 views

Use Python to determine the repeating pattern in a string

I am writing an algorithm to count the number of times a substring repeats itself. The string is between 1-200 characters ranging from letters a-z. There should be no left overs at the end of the ...
3
votes
0answers
54 views

Parse path string

Suppose path string are encoded in this way: 2T3T5: means move 2 steps, turn right, move 3 steps, turn right, and move 5 steps 32T: which better read as 3(2T), and it means do the following operation ...
1
vote
1answer
50 views

Counting and scoring two- and three-word phrases

I am writing a function to take a list of words and score 2 and 3 word phrases based on occurrence while removing any phrase occurrences with a score of less than 3. As someone kinda new to python, i'...
4
votes
2answers
248 views

Loop through database and run shell commands with Python and exiftool

Briefly, I'm looking at getting the code below to execute faster. I have 100k images to go through. I'm running a query against MySQL, looping through results and then running exiftool against an ...
4
votes
1answer
220 views

Simplify the restructuring of json data

I am trying to ad nested to some flat data, which is nested. Basically this code works the following way: "taglevel":1 tags should be key of the array "taglevel":2 or higher tags should be nested ...
7
votes
3answers
471 views

Find the total number of ways W, in which a sum S can be reached in N throws of a dice

I was solving this question: Given there is a 6 sided dice. Find the total number of ways W, in which a sum S can be reached in N throws. Example: S = 1, N = 6 => W = 0 S = 6, N = 6 => W ...
20
votes
7answers
2k views

Check if a number N is a power of K

I was asked this question in interview: Check if a number N is a power of K. Example: N = 32, K = 2 => True N = 40, K = 5 => False I wrote following code but got the feedback that, ...
4
votes
1answer
103 views

Student Attendance Record II

I'm currently working on the Student Attendance Record II problem: Given a positive integer \$n\$, return the number of all possible attendance records with length \$n\$, which will be regarded ...
7
votes
1answer
41 views

Track changes inside a directory

I have built a Python 2.7 script to track all file and subdir changes inside a nominated directory. It is used with directories that have multiple levels of subdirectories, hundreds of thousands of ...