Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
3 votes
2 answers
298 views

JSON Lexer code

How does the following look for a json lexer? Are there any things that can be improved upon? Does the pattern look general-purpose enough to be able to generalize it to make it into a useful program, ...
David542's user avatar
  • 429
0 votes
1 answer
2k views

Function to add a new key pair value to my JSON file

As you can see I am using a counter variable to iterate through my JSON file and it's a dictionary that has a list of dictionaries. Once I find the key normalHours I divide it and add it to my ...
JThao's user avatar
  • 37
1 vote
1 answer
134 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 ...
Evil2's user avatar
  • 11
0 votes
1 answer
195 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 ...
User1974's user avatar
  • 198
0 votes
1 answer
47 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 ...
JThao's user avatar
  • 37
1 vote
1 answer
3k 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 ...
JThao's user avatar
  • 37
1 vote
2 answers
1k 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. ...
JThao's user avatar
  • 37
3 votes
4 answers
2k 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 ...
Saya's user avatar
  • 137
1 vote
0 answers
214 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 ...
User1974's 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 ...
jeronimo dcosta's user avatar
5 votes
1 answer
1k 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 ...
Alex's user avatar
  • 151
8 votes
2 answers
3k 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 ...
Cheppy's user avatar
  • 83
2 votes
0 answers
43 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'...
keves1's user avatar
  • 21
3 votes
0 answers
54 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 ...
SlavaB's user avatar
  • 31
2 votes
3 answers
607 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 <...
Justin's user avatar
  • 2,485
4 votes
0 answers
291 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 ...
JeremiahDixon's user avatar
5 votes
4 answers
937 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: ...
DapperDuck's user avatar
3 votes
1 answer
82 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: ...
User1974's user avatar
  • 198
1 vote
2 answers
799 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? ...
gss's user avatar
  • 169
3 votes
1 answer
845 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. ...
User1974's user avatar
  • 198
12 votes
3 answers
2k 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). ...
Fivesideddice's user avatar
2 votes
1 answer
179 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 ...
Emma's user avatar
  • 3,542
2 votes
0 answers
142 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 ...
3sm1r's user avatar
  • 143
2 votes
1 answer
116 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,...
User1974's user avatar
  • 198
5 votes
1 answer
377 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 ...
User1974's user avatar
  • 198
2 votes
1 answer
76 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 ...
3sm1r's user avatar
  • 143
2 votes
1 answer
129 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 ...
SimonT's user avatar
  • 163
0 votes
1 answer
528 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 ...
Enrico Mosca's user avatar
6 votes
3 answers
1k 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 ...
martixy's user avatar
  • 253
1 vote
1 answer
36 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 ...
user3680510's user avatar
2 votes
1 answer
383 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: ...
Karn Kumar's user avatar
0 votes
1 answer
6k 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 ...
Daniel Bertoldi's user avatar
3 votes
1 answer
291 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 ...
random_dsp_guy's user avatar
2 votes
2 answers
168 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 ...
myang0630's user avatar
  • 564
3 votes
0 answers
294 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: ...
Ciasto piekarz's user avatar
1 vote
0 answers
83 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 <...
Ibrahim Rahimi's user avatar
1 vote
1 answer
206 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 ...
Ibrahim Rahimi's user avatar
2 votes
1 answer
48 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 ...
User1974's user avatar
  • 198
7 votes
1 answer
174 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
1 vote
1 answer
68 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 ...
John Doe's user avatar
  • 113
2 votes
1 answer
308 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 ...
Nick's user avatar
  • 21
0 votes
1 answer
139 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? ...
Hunter's user avatar
  • 11
5 votes
1 answer
215 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 ...
FallenSpaces's user avatar
3 votes
1 answer
723 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 ...
Akanksha's user avatar
  • 129
6 votes
1 answer
216 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 ...
Cutton Eye's user avatar
2 votes
1 answer
473 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 ...
LRDPRDX's user avatar
  • 831
1 vote
3 answers
52 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: ...
Quuxplusone's user avatar
  • 19.4k
4 votes
2 answers
347 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 ...
pythonoob's user avatar
1 vote
1 answer
239 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, ...
Helana Brock's user avatar
5 votes
2 answers
292 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 ...
lc74's user avatar
  • 51

1
2 3 4 5
25