Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
32 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 ...
4
votes
0answers
21 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. ...
7
votes
2answers
50 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 ...
3
votes
1answer
60 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: ...
2
votes
1answer
56 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 - ...
3
votes
0answers
30 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 ...
2
votes
2answers
51 views

Trellis Generator

I've been tasked with writing a simple trellis generator. The user is prompted with entering the height and width of the desired trellis, and gets a printed result of a trellis with the entered ...
5
votes
1answer
309 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 ...
5
votes
2answers
61 views

Generate EFF diceware passwords with Python

I wanted to write a commandline scipt to generate diceware passwords based on the EFF diceware list. The script (diceware_password.py) can be found below. It was ...
4
votes
2answers
69 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 ...
6
votes
1answer
68 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 ...
-2
votes
1answer
50 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 ...
3
votes
1answer
103 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 ...
3
votes
2answers
52 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....
1
vote
0answers
37 views

Choose numbers from a grid, minimising the sum

Given a 2-D input matrix, I need to pick elements from it. constraint: you can pick one number at each row, each column given: number boards are given expected output: print least sum of ...
3
votes
0answers
81 views

Python Type System

Problem Statement: I am writing Job Scheduling software in Python. I expect users of this software to provide Job definition in XML like format. For example: ...
2
votes
3answers
74 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
138 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 ...
2
votes
2answers
77 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, ...
4
votes
1answer
137 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 ...
2
votes
1answer
60 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
1answer
60 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 ...
1
vote
0answers
26 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 ...
3
votes
3answers
2k views

String compression function in python code [closed]

I need to create a function called compress that compresses a string by replacing any repeated letters with a letter and number. Can someone suggest a better way to do this? ...
6
votes
3answers
556 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. ...
5
votes
3answers
168 views

Python code for buffer creation and intersection

The script below uses an ArcPy package which helps to create buffer of the impact around a location where a blast occurs(user entered), intersects with building footprint which is the point of ...
4
votes
3answers
413 views

Pet hotel system in Python

I am doing a simple application for a pet hotel. I have almost finished but I'm still new on Python and I would like to see if there is a more efficient way to write this. My next steps would be to ...
3
votes
1answer
146 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 ...
1
vote
1answer
43 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
40 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 ...
2
votes
0answers
81 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 ...
3
votes
2answers
359 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
31 views

MinMax product for large matrices

I created this program which runs with no error, but I'd like to have some comments if it is possible to optimize it, since I need to run the program with N = 3200. ...
1
vote
1answer
53 views

Replace characters using multiple dependent regular expression substitutions

I've written the following Python module to iterate over field values in the following two fields: "NAME_LABEL", "CATEGORY". I'm using regular expressions in the following function: "...
0
votes
1answer
52 views

Python Readability for SQL query [closed]

I have this piece of code in Python 2.7: As you can see is very hard to read the SQL query, what is the best way to re-write it? ...
3
votes
0answers
99 views

OLED display application for Raspberry Pi

Python script to output status information to a small OLED screen connected to a Raspberry Pi. I'm relatively new at writing python so although the app works and outputs correct information it is far ...
2
votes
1answer
39 views

Looping text in Python with directional control

The code is an implementation of looping text (similar to a circular buffer - wraps around when it reaches the edge of the defined bounds) with directional control. The code is functional and works ...
5
votes
2answers
137 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 ...
-1
votes
1answer
106 views

Decoding a string encoded by Caesar Cipher and some delimiters [closed]

I have the following code which I seek to optimize. The result of the bruteforce I already have but I'm just trying to learn some more python using the same example. The code in the data needs to be ...
2
votes
3answers
114 views

Code to find the sum of the product of all size-n combinations of an array

The title is a bit of a mouthful, so here's a quick example: You've got an array, maybe just the digits 1-3, and you want to get the sum of product of all size-2 combinations of the array. Those ...
3
votes
3answers
190 views

Function to test for different conditions in input data

I have the following function that checks a data record to see if it has met certain criteria specified separately in configuration settings. The configurations are set up as a list of dictionaries ...
0
votes
1answer
39 views

Printing all the factors as well as the prime factors of a given number using Python 2.7.x

Okay here is my maiden attempt at programming using Python 2.7. I need help or feedback on this code: How do I know about the processing cycles this program consumes? How do I implement this idea ...
7
votes
1answer
346 views

Printing factors and prime factors of a number

I am a 46 year young newbie trying to learn programming for fun and adventure. I do this in my free time. Some very nice gentlemen on stackoverflow have sent me here. I wish that someone could review ...
2
votes
0answers
46 views

How to make my neural network train faster

I'm trying to train my neural network and for the most part it's going well. However, I'd like it if it could train faster and was wondering if anyone could give some advice. I'm trying mostly to ...
3
votes
2answers
224 views

Python 2.7 Powerball Game

This game allows one to either pick their own lottery numbers or have them generated and checks them with the most recent numbers, jackpot, and multiplier. I use concepts such as ...
6
votes
1answer
120 views

Simple CLI Python Hangman game

Preamble: I am very new to Python, and outside of Googling functions and a former work colleague telling me why I'm wrong, I have no formal training and haven't taken any "Learn Python" courses. I ...
4
votes
1answer
66 views

Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
7
votes
2answers
827 views

Generate Letter Combinations of a Phone Number

The task: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. and my solution: ...
1
vote
0answers
89 views

Quora upvotes trends Hackerrank challenge

The following code is my solution to an old problem I found today. Input Format Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N) Line 2: N positive integers of upvote ...
8
votes
2answers
53 views

Streaming scheduled TV shows according to a CSV playlist

I'm very new to Python, and I've made a small program/script that will allow me to stream specific files at a given time. My idea is that I have a .csv file for each day, with one row for each movie/...