Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [python-2.x]

Python 2 is the predecessor of Python 3 and its last version, Python 2.7 was formally released on July 3, 2010. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 2 interpreter only. Do not mix this tag with the python-3.x tag.

Filter by
Sorted by
Tagged with
4
votes
1answer
404 views

Bidirectional BFS on a matrix in Python 2.7

This code is a bidirectional BFS search. Given any two points in a matrix having 0's and 1's, I would like to find if there exists a path between them. Also note that it is forbidden to enter a cell ...
4
votes
2answers
116 views

Marking projects as done when all tasks' progress are 100%

We have project.task model, where each task has many lines and each line has progress field indicating how much work has been done and how much still remaining (...
2
votes
1answer
62 views

Adding a new record automatically

I created this method that adds a new situation to the situation list. The situation has a many-to-one relation with project.task. This method seems a little longer than it should be and I don't know ...
2
votes
0answers
330 views

UK Tax Calculator - First Python program

This is my first Python program and while it's not quite finished I would like to know how I could improve in general as a programmer. This project has be a lot of fun but it has felt more like ...
1
vote
1answer
122 views

Translating a Haskell data to Python

I've been working on a project in python, and I needed to represent a certain numeric type. I need to represent the concept of some or all. Then I need to be able to add these amounts. Coming to ...
3
votes
1answer
53 views

Sorting by checking 2 distance away elements in a list, and check the method's accuracy

This code works as follows : It accepts number of test case T. For each test case, it accepts length of sequence of integers N and the sequence (or list) itself L. The goal is to sort the list by ...
5
votes
2answers
18k views

Binding a keyboard key to a Tkinter button

I'm specifically asking about binding a keyboard keystroke to a button in a GUI. Originally I planned to bind the keystroke to the GUI button itself, but that seemed impossible, and potentially unwise ...
8
votes
1answer
110 views

Parse ping log to find total downtime

Trying to write a utility script to get downtime measurements from ping logs which generally look like this: ...
8
votes
2answers
353 views

Calculate electric field of a charged annulus

This script calculates the shape of the electric field on a 2D grid perpendicular to a uniformly charged annulus using SciPy's dblquad (tutorial, documentation). I'...
3
votes
2answers
334 views

GUI interface for company specific calculator

I created a customised GUI application in Python, which is a calculator that does some basic functions for my company. I would like to ask you for overall suggestions for code improvement. ...
4
votes
0answers
317 views

Fetching Facebook Places API [closed]

I am pretty new to Python as a frontend dev and I loved it, so I started to build a tool fetching the Facebook Places API. I don't know where to optimize it but I need you to take a look at my code ...
1
vote
1answer
3k views

Generating JSON with Jinja2

I needed quickly to represent a list in json format. I wrote the following front-end in jinja2 with google appengine. ...
4
votes
3answers
2k views

os.walk listing directory

I use this script to get a list of all my photos in a folder and its subfolders. However, the program seems to be really slow. There are 50,000 .jpg pictures in this folder and subfolders. I can ...
7
votes
2answers
119 views

Simulating surname convergence in a population

I was curious a few weeks ago about how surnames come and go (mostly on the go). I wanted to know how quickly surnames die out, because (in my simplified simulation world) once the last person with a ...
1
vote
1answer
277 views

Groups/Communities in Facebook snap dataset using networkx in python

I was using facebook dataset and making a graph on it. But was not been able to find different groups/communities in it. The code was using is this: ...
20
votes
6answers
18k views

Python code to retry function

I am trying to write a python function which retries a given function until given time or function returns True with given delay. I have written the following function, but was thinking if there is ...
4
votes
3answers
227 views

Formatting the opposite of some numbers, with decimal alignment

Background I have a list of strings containing numbers. Each string is 8 characters long. For example : ...
4
votes
1answer
167 views

Updating data file records

I learnt to code a long, long time ago. Concerns Existing approach is messy and will be hard to maintain. System errors are not trapped and the error messages could be better implemented. Final ...
3
votes
1answer
527 views

Script to store, search, and delete IPFS data with description in JSON file

Here is the script that I would like reviewed for the following: Best practices and design pattern usage Correctness in unanticipated cases Better dictionary access The script is made to store (IPFS)...
-2
votes
1answer
95 views

How to make this code more compact and readable

My below code is working fine but I want to make it more Pythonic. Furthermore, I want to get rid of nested ifs and make the code more compact and readable. Any suggestions? Here project_id and ...
3
votes
1answer
49 views

Preliminary draft of a data structure for a goodies tracker

My girlfriend and I are making a goodies tracker to enable us to keep better track of our stamp/gift cards. Right now we've got a super simple Object with some fields of what a stamp card has, and no ...
7
votes
1answer
116 views

Hangman game, with the number of guesses depending on the word length

This is an interactive game between the computer and the player, where the computer chooses a word and the user has to guess the letters in that word. The computer provides certain number of guesses ...
11
votes
1answer
7k views

Simple two-player Tic-Tac-Toe

How can I improve this simple code to look better, concise and elegant? I've been learning Python for 2 weeks. I knew about basic Python stuff and some algorithms and data structure as well. I made a ...
7
votes
2answers
627 views

Repeatable HTTP requests in Python

I have a simple python script that's repeating a HTTP response/request. I would like to know how I could have constructed this better, particularly if there's a way I could have incorporated the slice ...
5
votes
1answer
687 views

Python: wild card pattern matching with memoization

Here is my take on wild card pattern matching with memoization. I would appreciate comments on clarity of the code, as well as suggested ways to improve readability and maintainability (for bigger ...
4
votes
1answer
122 views

2D discrete motion planner

I am writing a 2D discrete motion planner for a task with specific instructions. The instructions for the search algorithm are contained entirely in the docstring for the ...
2
votes
0answers
222 views

Convert python's strftime directives to user-friendly format examples

I'm converting python's very un user-friendly strftime date time directives to user-friendly formats so that users of an API will know how to format a date if they send an invalid format. My thinking ...
1
vote
4answers
1k views

Print all permutations from a given list of strings such that each set of strings is completely unique

Problem : Given a list of strings, some of which may be anagrams amongst themselves, print the permutations which can be so constructed so that each permutation has set of strings which is completely ...
1
vote
1answer
80 views

Transforming lists of products to boolean vectors

Task Inputs Lists of products stored in a CSV file, where each line represents the shopping list of a single client: Outputs A CSV file: Header: products names sorted by number of appearances in ...
3
votes
1answer
738 views

Find spiral 2D matrix (List of Lists) of ints in a clockwise spiral

I got this question during my interview with Microsoft. The question called 2D Snake. I'm wondering if my solution 1 passes the test, but if my solution 1 different from solution 2. Let's have ...
13
votes
1answer
348 views

Voting plugin for an IRC bot

MetaBrainz has an IRC channel called #metabrainz on which there's a bot called BrainzBot running. It provides utilities such as linking to JIRA issues or Github PRs ...
8
votes
2answers
1k views

Print a random anagram of a given string

I am given a task to create a function that prints a random anagram of a given string: ...
1
vote
0answers
472 views

Protection from SQL injection

I have this code, which is working correctly, but I am sure that it allows SQL injection attacks. ...
4
votes
2answers
157 views

Persistent, dictionary-like object ensurance

This is a part of a project I'm working on. The codebase is Python 2.7 and I don't have an option to switch to Python 3. Code: ...
1
vote
1answer
74 views

File names to database table

I have files in subfolders on a network drive. I want to create a list of files, and insert that list into an Oracle table. I can successfully iterate through the files in the subfolders and do the ...
4
votes
2answers
631 views

Finding palindromic strings of even length

Given a string of digits. Find the length of longest substring of even length i.e. 0,2,... which is a palindrome or which can be rearranged to form a palindrome (see example below). Here is my code: ...
8
votes
1answer
376 views

Animation of linear transformations

Coordinates Given a 2d space, we can fix a coordinate system to talk about transformations numerically. The red vector, that ends at (1, 0) and the green vector that ends at (0, 1) are called the ...
4
votes
1answer
107 views

A word replacer that uses an API to check for different words to make up a new string

This is one of my first finished programs that I've written to date. I am not yet very familiar with Python, so please bear with me. I'd like to know from you: Can my code be called 'pythonic'? I'...
10
votes
2answers
3k views

Data encryption with python

I am just trying to solve one of the puzzle which is explained below: The sentence if man was meant to stay on the ground god would have given us roots after ...
1
vote
2answers
2k views

Reversing the bits of a 32-bit integer

Here is my code: ...
4
votes
3answers
563 views

Basic python dice simulator with log function

I had created a dice simulator using nothing but functions, but I wanted to attempt one using a class for the dice just to help get a better understanding of classes. I'm still a little in the dark ...
6
votes
4answers
1k views

Solving jumbled letters using a given dictionary

Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters. Example: ...
1
vote
1answer
161 views

The Substring Game! challenge

This is the Substring Game! challenge from HackerEarth: Watson gives Sherlock a string (let's denote it by S). Watson calculates all the substrings of S in his favourite order. According to ...
4
votes
1answer
136 views

Scraping data from Bureau of Labor Statistics website

I'm currently scraping this website Bureau of Labor Statistics and I just want some feedback on how my approach was. I'm mainly focusing on the occupation groups table to the left of the website and ...
4
votes
0answers
54 views

Improving SVM fitting accuracy

I have this attempt on classifying CIFAR10 images. I'm curently training my SVM only on 1 of 5 sets, and decided on using polynomial kernel(degree=3,C=0.1 [changes have no effect],gamma=2 [changes ...
22
votes
5answers
46k views

Replacing letters with numbers with its position in alphabet

If anything in the text isn't a letter, ignore it and don't return it. a being 1, b ...
22
votes
1answer
306 views

Raspberry PI controllable Christmas Tree

After having the scales, thermometer and a coffeemaker connected to the internet, it is finally time for Christmas Tree to become smarter. Hardware 6ft Christmas Tree An addressable WS2811 LED strip ...
6
votes
2answers
1k views

Remove outliers from a point cloud

This function accepts a cloud of points, and returns those points that are within delta distance of the average (mean) position. ...
1
vote
1answer
549 views

Calculating the percentage on Python 2.7

An attack with magnitude M will be successful with a chance of (100-M)%. That is, higher magnitude means higher risk of missing it. For instance, if M is 30, the chance of succeeding would be 70%, ...
5
votes
2answers
127 views

Status Report sending using python

I used this script to sending status report to my team lead. It will read the status from the file Readme.md. Here i already wrote my status. if this script execute on target_time or greater than it ...