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
1 answer
54 views

Register/Login for Rock/Paper/Scissors

Recently I have been learning Python after years of putting it off, and I am having a really fun time with it. However after I spent a few hours making something that I thought was pretty cool, I ...
user avatar
  • 11
0 votes
0 answers
32 views

leetcode 247 Strobogrammatic Number II

I tried to solve leetcode 247 Strobogrammatic Number II. Question is ...
user avatar
0 votes
1 answer
81 views

Loop through polyline vertices and update coordinate

I have a Python 2.7 script that loops through GIS polylines and updates a coordinate. The coordinate is called an "M" coordinate (aka a "Measure-value"). M coordinates are similar ...
user avatar
  • 198
0 votes
1 answer
37 views

What other checks do I need for removing files after X amount of days?

I am trying to remove files in my directory if they are over 30 days. However I don't know what other checks I need to do. The examples I found online wasn't very thorough besides just subtracting the ...
user avatar
  • 25
1 vote
1 answer
114 views

What is the pythonic way to update my nested dictionary?

So I need to update my nested dictionary where the key is "compensationsDeltaEmployee". I created a string cost_perhour to hold the value of my conditional statements. Now that I am done ...
user avatar
  • 25
1 vote
2 answers
106 views

Is there a faster way to write dictionary values to csv?

I have a dictionary that I am writing to a csv file, however I am only writing the values. I want to know if there is a faster way than using a for loop. I am using python 2.7 here is my code. ...
user avatar
  • 25
3 votes
4 answers
349 views

Find differences between two directories

Coming from another language than Python, I would like to see if my code is "pythonic" enough and follows good practices. It compares two directories, showing all files that are in one and ...
user avatar
  • 137
1 vote
0 answers
53 views

Script to check a web service

I'm a Python novice. The system I'm using is called IBM Maximo Asset Management. In Maximo, we can write Python scripts that utilize Maximo's Java API/methods. So the script is technically a Jython ...
user avatar
  • 198
8 votes
3 answers
3k views

Calculate evapotranspiration

I am trying to create a code for the Basic evapotranspiration equation by Hargreaves. I have attached a screenshot of the equation to be replicated. I want to create a class wherein I can input data ...
user avatar
5 votes
1 answer
228 views

Send email with attachments, including in memory zipped attachments

The below class implementing a simple way to create emails with attachments, including the option to create in-memory zip files and attach them to the email. Because I am not a professional programmer ...
user avatar
  • 151
8 votes
2 answers
332 views

log setup using RotatingFileHandler and basicConfig

I am new to python, and developing a moderate application for which I need to setup a logging mechanism. The below program sets up log handling, which gives the user an option to specify whether log ...
user avatar
  • 83
2 votes
0 answers
29 views

Interactive, real-time bikeshare web application with Bokeh

As a side project, I'm working on a Bokeh web application to display public bikeshare data on a map. The data is updated every 2 minutes using a periodic callback. Below is the full implementation. I'...
user avatar
  • 21
3 votes
0 answers
47 views

Python script that getting list of all files with specific ext starting from the current folder. Using timer for reporting about the process

I am using a function that returns a list of all files (full path for each of them) with the given extension in the given folder and all subfolders. As the process is quite long and user can get ...
user avatar
  • 31
2 votes
3 answers
595 views

Bifurcating recursive calculation with redundant calculations

def T(n): if n <= 0: return 1 else: return T(n-1) + (n-1) * T(n-2) print T(4) I need an effective way to print out the output of the function <...
user avatar
  • 2,460
4 votes
0 answers
102 views

Simple chat server in Python

I'm new to both Python and socket programming and figured setting up a simple chat server would be good practice. In addition to general critiques of the code, I have specific questions: What are the ...
user avatar
5 votes
4 answers
509 views

Decrease Computation Time for Python Tic-Tac-Toe Minimax Algorithm

Background I am currently participating in a tic-tac-toe coding challenge. During their move, each participant is given the board state and their team, X or O. The blank board is: ...
user avatar
3 votes
1 answer
41 views

Parse backslash-delimited hierarchy path into separate columns

I have rows in a database table with a hierarchypath column. The values in the column are hierarchy paths with up to four levels: ...
user avatar
  • 198
1 vote
2 answers
406 views

Python Regex to validate an email

I have written this regex to validate an email. It seems to work fine. Can someone advise on the regex used? Does it work properly or can be done in a better way? ...
user avatar
  • 169
3 votes
1 answer
240 views

Determine if points are within a rotated rectangle

Using only Python 2.7 and the standard library (no imports): Determine if a point is inside the rotated rectangle. ...
user avatar
  • 198
12 votes
3 answers
1k views

Finding the prime factors of a number in Python 2

I’ve created a function that takes a number and, if it’s prime, tells you so, or if it’s composite, gives you the prime factors of the number (and if it’s 1, tells you that it’s neither). ...
user avatar
2 votes
1 answer
114 views

LeetCode 839: Similar String Groups III

I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Thank you! Problem Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that ...
user avatar
  • 3,369
2 votes
0 answers
79 views

Find the available squares for rooks in empty board using boolean arrays

I will describe two techniques, then the question will be how I can make an algorithm that is more efficient, if possible. I want to find an efficient way to determine the squares where the pieces on ...
user avatar
  • 143
2 votes
1 answer
74 views

Part 2: Create or update record via HTTP request

This script was previously reviewed here: Part 1: Create or update record via HTTP request I've made the changes that were suggested by @Reinderien. Now that the code has been significantly refactored,...
user avatar
  • 198
5 votes
1 answer
234 views

Part 1: Create or update record via HTTP request

Update: This is an older version of the question/script. The new version can be found here: Part 2: Create or update record via HTTP request I have an external system that sends an HTTP request to a ...
user avatar
  • 198
2 votes
1 answer
65 views

Updating a dictionary of trajectories after a step has been made

I am using a dictionary to save possible trajectories in a game. A trajectory is defined as a list of numbers separated by _. For example ...
user avatar
  • 143
2 votes
1 answer
121 views

Python - Do I need a class or are these functions okay?

I'm fairly new to Python but had to start using it and for reasons I have to use 2.7, which is why I am using that syntax. I have this function which gets data from a file, if it exists, and then gets ...
user avatar
  • 163
0 votes
1 answer
121 views

Image color-moment extractor [closed]

I was just wondering if there is a way to speed up the performances of this for loops in Python. I'm trying to process an image to get the color-moments without using libraries. It takes about 12sec ...
user avatar
6 votes
3 answers
923 views

Prime sieve generator

I wrote a simple prime sieve in Python. But it ended up looking... ugly. I included a few of the most basic optimizations. When posting this question SE suggested a bunch of questions on the same ...
user avatar
  • 253
1 vote
1 answer
34 views

Selecting minimal sum of two distinct entries of two dicts with common keys

Can this function simplified? The goal is return one key from each dictionary (both contain the identical keys), so that the sum of the values that belong to the selected keys are minimal (and also ...
user avatar
2 votes
1 answer
153 views

Linux bonding status check

I have created the below code which works for me, but I feel there might be a better way to accomplish this in a new Pythonic way or better Python syntactic way. Code snippet: ...
user avatar
0 votes
1 answer
4k views

Foo Bar - Power Hungry challenge test case failing on unknown edge cases [closed]

The challenge is to find the maximum product of a subset of a given array. Here's the problem: Write a function solution(xs) that takes a list of integers representing the power output levels of ...
user avatar
3 votes
1 answer
160 views

Estimation of min_samples for DBSCAN

I'm attempting to speed up some python code that is supposed to automatically pick the minimum samples argument in DBSCAN. Currently the execution time grows exponentially as the number of training ...
user avatar
2 votes
2 answers
136 views

Python - Hexadecimal to Decimal conversions

I have written a python 2 program for a school project to convert from hexadecimal to decimal without using built-in functions and vice versa in python. I would like to know how I can make my code ...
user avatar
  • 554
3 votes
0 answers
176 views

Store special deals, like 3 for 2

I have to apply two deals on the cart. Buy 3 (equal) items and pay for 2 Buy 3 (in a set of items) and the cheapest is free Items in cart: ...
user avatar
1 vote
0 answers
52 views

Reading attachment data from a PostgreSQL table with python

I have developed this script to find the counts of attachment records stored in a table in PostgreSQL for different other tables. I check if the res_id field of <...
user avatar
1 vote
1 answer
193 views

Reading employee data from a PostgreSQL database

I have developed this script to read employee_language table records of a PostgreSQL database using Python 2 (due to some OS limitation). I want to find duplicate ...
user avatar
2 votes
1 answer
41 views

Reload polyline midpoints into parallel tables

I have an Oracle GIS database that has spatial tables. The records in the spatial tables have a geometry column that contains polylines. I've written a Python 2.7.16 script that calculates the ...
user avatar
  • 198
6 votes
0 answers
69 views

Python - Displaying messages in ArcPy/IDLE

I have created a wrapper for displaying messages with ArcPy and IDLE (as that is all I have available to myself due to certain circumstances) as I frequently use both to test and develop new tools. ...
user avatar
  • 69
1 vote
1 answer
52 views

Executing Scipy Tensor Product [closed]

Can anyone advise on how to use the SymPy TensorProduct function without having to explicitly indicate the full sequence of objects to take the product of. Below (for the simple case N=3) you can see ...
user avatar
  • 113
2 votes
1 answer
214 views

Weaving multiple lists into one

I have this code to weave the split_input ['5,4 4,5 8,7', '6,3 3,2 9,6 4,3', '7,6', '9,8', '5,5 7,8 6,5 6,4'] together. However I feel like this can be done more ...
user avatar
  • 21
0 votes
1 answer
116 views

Pyg Latin Translator [closed]

I have a code for a short Python 2 Pig Latin translator. Is it a good code, or should it be revised? ...
user avatar
  • 11
5 votes
0 answers
123 views

Python Project Template

What's up smart people. A little backstory for context: I'm a completely self taught dev, and the only person ever looking at my code for the past 6 years is myself. I realize that's not the best idea ...
user avatar
3 votes
1 answer
425 views

Simulate Tic-Tac-Toe game in Python

Simulate a tic-tac-toe game Requirements A player is picked at random as a first player. The two players plays tic tac toe game. The game ends when the board is full or either one of the player ...
user avatar
  • 129
6 votes
1 answer
174 views

Universal string conversion

Below there is a function eating all strings and convert it to Unicode. It works fine. But is it the best way to do so? Is there maybe already an existing function for it? The reason was a German ...
user avatar
2 votes
1 answer
290 views

An imitation of reading a C Struct from binary file in python 2.7

Preliminary I need to read a binary file constructed by writing a Struct to it with Python. So I decided to write a simple wrapper using ...
user avatar
  • 771
1 vote
0 answers
89 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 :...
user avatar
1 vote
3 answers
43 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: ...
user avatar
4 votes
2 answers
237 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 ...
user avatar
1 vote
1 answer
134 views

Django view of reward points that heavily filters and sorts (many) database results

My page (even when it has no data) takes 10+ seconds to load. That's just too long, considering when you finally get to it there's no data. When it has data, it takes even longer. Here is my view, ...
user avatar
5 votes
2 answers
189 views

Program to delete directories that do not contain a file

I'm an intern and have an ETL project I'm doing in python. Part of it is to make sure after I move files I delete empty directories. I wrote this code to clean up directories that are empty and in ...
user avatar
  • 51

1
2 3 4 5
25