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
1
vote
0answers
81 views

AWS plugin to create a CloudFormation stack if it doesn't exist

The following Python class is what I am trying to refactor in the case where I have to add validation of the existence of an AWS cloudformation stack before creating it in the method create_cfn_stack :...
1
vote
3answers
41 views

`set_includes` (string subsequence-containment) in Python 2

I've implemented C++'s std::includes algorithm in Python, so that I can use it to efficiently implement a Scrabble "can I make this word" function: ...
3
votes
2answers
1k views

Weaving rows of numbers

I want to write a cleaner version of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my ...
5
votes
2answers
776 views

Prime Number Generator (6n + 1 or 6n - 1)

This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares ...
4
votes
2answers
196 views

Print a pattern of text based on a line from an Excel file

I started to learn Python not long ago to automate certain tasks I work on. I want to optimize a script I wrote that takes a line in an Excel file and prints a pattern of text based on this line's ...
10
votes
1answer
8k views

Given a string, find the length of the longest substring without repeating characters

I wrote an algorithm that solves this problem but I would love to get some feedback on it (especially since I'm not so confident in my Big \$O\$ skills). Do you think this is a good quality algorithm?...
25
votes
4answers
16k views

Validating Credit Card Numbers

This is one of the puzzles I was trying to solve, where the question is to validate the credit card number with following characteristics: It must contain exactly 16 digits. It must start ...
3
votes
0answers
155 views

Animation of an incremental rotary encoder

While reworking my teaching materials for an exercise of an introductory course on mobile robotics, I recently created a animation/simulation of an incremental rotary encoder, e.g. often used for ...
2
votes
0answers
84 views

Extract cell values from multiband rasters

I have the following function and code snippet to extract cell values for multiple years, format it, and save to a list. Each raster has 365 bands — one for each day. A separate operation is performed ...
7
votes
2answers
1k views

Count reoccurring elements in multiple lists in Python

I have a number of names divided into several lists. I am printing all the names which occur in more than one list, sorted by the number of occurrences. What is a better/easier/more pythonic way of ...
4
votes
0answers
42 views

Combining CSV files of simulation results

This script is a subset of a larger script where I have the output of many test simulations in the form of CSVs. Each file starts with the model name and includes the number of elements in my file. ...
2
votes
1answer
2k views

Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
5
votes
1answer
114 views

Run a command for all files in a directory

I have a program that needs to run an command on all the files in a folder: ...
5
votes
3answers
13k views

Diagonal difference

Given You are given a square matrix of size \$N×N\$. Calculate the absolute difference of the sums across the two main diagonals. Input Format The first line contains a single integer N. The ...
2
votes
1answer
258 views

Reverse shell allows connection between computers

I've recently made a reverse-shell which allows you remote shell access to other computers. It's written in Python 2 and it is cross-platform. Basically, it get's user input for a command and sends ...
3
votes
0answers
57 views

Pygame : processing speed independant image loop displayer

I made this in order to teach myself pygame. This displays an images loop at the same speed on any computer (It will lag on a slow computer). Is my time management good or do my datetime call could ...
5
votes
2answers
588 views

Python optimized base64 writer for streamed files

I needed to make a base64 file encoder where you can control the read buffer size. This is what I came up with and it's quite fast. It might be able to be simpler but still maintain its performance ...
12
votes
2answers
2k 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
660 views

Improving the speed of creation for three Perlin Noise Maps in Python?

I am interested in learning how I can improve the speed of the code in this pygame file. I iterate over 6400 * 1800 * 3 or 34,560,000 elements of various numpy arrays here to apply noise values to ...
4
votes
2answers
530 views

automating to push changes to github for multiple repos using python

This Python script does following activities: clone repo, as provided from the list creating a new branch "jenkinsMigrate" rename Jenkinsfile to Jenkinsfile.migrate push code to GitHub in a new ...
7
votes
1answer
377 views

Plotting terrain pixels with PyGame based on random NumPy array

I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list that I call from the singleton ...
4
votes
2answers
4k views

Twin Prime Algorithm Optimization

I have wrote the following algorithm to print out the Nth twin prime numbers: ...
-2
votes
1answer
56 views

Functional vs non functional approach in python [closed]

This is not a task, but I want to know what the general consensus is on functional programming. Particularly functional programming in Python. The two snippets of code I am comparing are the ...
8
votes
1answer
131 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: ...
3
votes
1answer
134 views

First python program: basic calculator

I want to start learning python for fun and so I could dig into machine learning projects later in the future maybe. I started off with a small calculator project just to get the hang of the language ...
7
votes
1answer
2k views

Builder - A 2D Minecraft clone

I was poking around on my Raspberry Pi that I hadn't turned on or used in a while, and I stumbled upon this Python script that I wrote ~1.5 years ago, and I was intrigued. Essentially, it's a 2D ...
3
votes
2answers
25k views

Find the median value of a list

I am taking an online training course on Python, and am at the following question: Write a function called median that takes a list as an input and returns the median value of the list. For ...
3
votes
2answers
3k views

Capitalize a sequence of lines entered via console input and print/return

I'm running through the popular python practice exercises located at github: https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises....
2
votes
1answer
4k views

Recursively list files within a directory

I have the following code to recursively list files within a directory: ...
9
votes
2answers
1k views

Blackjack game in Python 2.7

Please review my game. I am learning Python now, so any suggestions are welcome. I am running this on a Linux machine, in Komodo and terminal. ...
12
votes
1answer
2k 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 ...
2
votes
1answer
83 views

Application to monitor device power levels for deviations

I have a high performance, computation intensive application that runs on a Centos 7 machine with Python 2.7.5. I'll try to explain what the application does: The application runs an infinite loop, ...
2
votes
3answers
171 views

Free time calculator

I started learning Python 2 about a week ago, using Codecademy and Stack Overflow answers to help me learn. I wrote a code to calculate the user's free time based on user sleep and work time. It also ...
4
votes
2answers
2k views

Guess-the-number game by a Python beginner

For some background I'm pretty much a beginner and attempting to learn Python currently. So I decided after a few days of lessons I'd look for some beginner projects to test my knowledge. A website ...
4
votes
1answer
286 views

Looping through multiple regex efficiently

I'm writing a program that adds all network interfaces with multiple parameters to a list. I have written the following code, which should work out of the box on any Linux system with Python and ...
1
vote
1answer
78 views

Python Firewall-Connection-Event Filter too slow

I've written a little piece of code to filter Firewall-Connection-Events by a certain group of IPs. But the code can't keep up since the input is fairly huge. I am looking for ways to make this code ...
2
votes
1answer
74 views

Most efficient way to find spatial order from a list of tuples (Python)

I have a circle-growth algorithm (line-growth with closed links) where new points are added between existing points at each iteration. The linkage information of each point is stored as a tuple in a ...
1
vote
0answers
83 views

Managing multiple sockets in a network client in Python

I'm writing a small FIX client in Python (2.7, constraint I cannot waive for now, unfortunately). There will be multiple sockets, connecting to different ports, so I thought I'd create a ...
2
votes
2answers
3k views

Serialize and deserialize binary tree

Here is my code of serialize and de-serialize a binary tree, looking for advice. One issue in my mind which I cannot resolve is, I am using a global variable index, wondering if more elegant solutions ...
6
votes
3answers
579 views

Implementing a customized helpful hints function which includes docstring but much shorter than Python help()

When I show others how to use this module I have them make a PROJECT instance and then add other objects. ...
22
votes
1answer
470 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 (...
4
votes
1answer
1k 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 ...
3
votes
1answer
331 views

Bin packing variant

As in classical bin packing problem, this is an algorithm that optimises the number of bins of a certain size used to hold a list of objects of varying size. In my variant I also work with a second ...
4
votes
1answer
11k views
10
votes
2answers
6k views

Dynamic unpacking in Python

Python lacks dynamic unpacking. Example: You want to unpack a list, let's say coordinates, but don't know whether it contains 3 items or just 2. x, y, z = [1,2,3] ...
1
vote
1answer
76 views

List directories, subdirectories and files, while ignoring some dirs

In my application, the user may or may not want to ignore some directories. I can do that, but it seems like I am repeating myself. Does anyone have an idea to refactor that? ...
0
votes
1answer
43 views

Analyzing distances between clusters of orders [closed]

I wrote the Python class below, which does what I want it to do, but the data structure is a mess. Was wondering if there was a better structure I could use to get the same results but with better ...
3
votes
2answers
3k views

Simple one time pad cipher

I had this idea not to long ago on creating a secure chat for people who need to be not meddled with when talking (like whistleblowers, hackers, etc) talking to one of my friends about it he said I ...
2
votes
0answers
163 views

Fully Constrained Least Squares (FCLS) Linear Spectral Mixture Analysis Method

I have written code using Python for Fully Constrained Least Squares (FCLS) Linear Spectral Mixture Analysis, which could be applied for unmixing multispectral image successfully. However, the ...

1 2
3
4 5
25