Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
3 votes
2 answers
97 views

Multiple condition checking on array-like container in Python

I'm writing a function that validates array-like container to have correct type, length or to be hashable. Some of conditions may not be used for validation. ...
user avatar
2 votes
1 answer
84 views

Replace nested for loops when assigning intial conditions in a 4-dimensional array

I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
user avatar
  • 69
1 vote
0 answers
14 views

Django data migration - worked, but far from performant

Background: I am learning web dev and decided on the Django framework as an excuse to learn Python at the same time. (Background is stats with lots of R and ...
user avatar
3 votes
0 answers
44 views

Scrape classifications from Wikipedia with bs4

I wrote my first bs4 script that scrapes animal classifications from Wikipedia. It works as long as the classifications are stored within these tags ...
user avatar
  • 131
2 votes
1 answer
74 views

Extract regular words from string but retain all other elements and record their type

This snippet processes every regular (\w+) word in a text and reinserts the processed version: ...
user avatar
  • 1,226
4 votes
1 answer
76 views

This function creates dynamic multi-choice questions

I'm into Python from only about a month, coming from nothing. I didn't make any complex program yet, but I'm almost there, as one is almost ready to be used, like if I'd sit there for another hour or ...
user avatar
1 vote
1 answer
84 views

Find next biggest palindrome

I have written a program for the SPOJ PALIN problem: A positive integer is called a palindrome if its[decimal representation is the same]from left to right and from right to left. For a given ...
user avatar
2 votes
1 answer
63 views

type hinting/documenting/extension of a Cython lib

I've updated some of the type hinting/documentation in a lib called pygrib. The source documentation can be found here. The goal is to extend the ...
user avatar
5 votes
2 answers
185 views

Count five-digit octal numbers with alternating even and odd digits, without repeated digits

I need to find the number of five-digit octal numbers in which all digits are different and no two odd or even digits are adjacent. My code below gives the correct answer, but I'm not satisfied. Can ...
user avatar
  • 53
1 vote
0 answers
21 views

RESNET machine learning code with TensorFlow

I am a PhD student working on a machine learning project with binary classification and RESNET architecture in TensorFlow. I believe I have done everything correctly but I am looking for some ...
user avatar
2 votes
0 answers
34 views

Variable speed video playback using OpenCV according to frequency of mouse clicking

Here's my code - I've a lot to learn so any advice, tips etc would be welcome! A few notes: I'm using OpenCV and numpy for other features in this code, not just for this snippet. The main readon for ...
user avatar
1 vote
0 answers
20 views

Algorithm for predict(start=start_date, end=end_date) on unique same named weather station [closed]

Problem on Algorithm for same like 'stations' Problem is to use weather data to run ARIMA model fit on each group of like named 'stations' with their associated precipitation data, then finally ...
user avatar
  • 111
3 votes
1 answer
109 views

The shortest path between airports

Airlines need to provide their customers with flights to every corner, so they need an app that allows them to do so. The customer must be able to transfer when there is no direct connection. The ...
user avatar
0 votes
0 answers
51 views

Extracting peak and peak width

I have a for loop where I want to read through multiple column of data pull out the peak and peak width data from each column using a predefined function. The loop ...
user avatar
1 vote
1 answer
43 views

change object column to numeric above cardinality threshold pandas

Is the following an acceptable way to change an object column to numeric if cardinality threshold (cardinality_threshold) is being breached? I think it would be good to check if column values are ...
user avatar
  • 631
0 votes
0 answers
49 views

Asynchronously download lists of scholarships

TL;DR There is a script here that handles async stuff. Another script imports that file and uses content from it as a "normal" function. Please help me evaluate my async code, I am new to ...
user avatar
1 vote
1 answer
50 views

performance - Word ladder leetcode

I am working on Word Ladder - LeetCode Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that: ...
user avatar
5 votes
1 answer
107 views

Looking for feedback on OOP for a trading bot on Kraken

I'm trying to build a Kraken portfolio bot and started out with a simple layout for loading the balances. If possible, I would like to get some feedback on this initial design. The API key provided is ...
user avatar
  • 59
1 vote
1 answer
68 views

Solving a 3D heat diffusion PDE

I am trying to solve a heat diffusion type PDE using a finite difference method. I would like to preface that I have seriously simplified the code. Just so that anyone who tries to help me, doesn't ...
user avatar
  • 69
4 votes
1 answer
222 views

A simple chatterbot using Tkinter in Python

I'm wrote a basic chatterbot. What would you do to pretty much improve it and make it better than this? Because I want this chatterbot to be the best it could be, and I really want other peoples' ...
user avatar
0 votes
0 answers
27 views

function for adding two 2D matrices of large size obtained by several iterations

I have defined the following function. ...
user avatar
  • 101
-1 votes
1 answer
40 views

Extraction of subsets by date and intervals from a dataframe with a specific date format

Given the following dataframe: ...
user avatar
  • 121
7 votes
2 answers
1k views

Automate the Boring Stuff CH 7: password strength test

This exercise comes from Automate the Boring Stuff Ch 7. The assignment is to use regular expressions to test the strength of a password. Password must be >= 8 characters, contain at least one ...
user avatar
  • 117
1 vote
1 answer
93 views

Optimise a function with numerous conditions that depends on the previous row in a Python dataframe

I have the following dataframe: country_ID ID direction date ESP_1 0 IN 2021-02-28 ENG 0 IN 2021-03-03 ENG 0 OUT 2021-03-04 ESP_2 0 IN 2021-03-05 FRA 1 OUT 2021-03-07 ENG 1 OUT 2021-03-09 ENG ...
user avatar
  • 121
2 votes
1 answer
68 views

dataframe mean outliers to NaN to derive a higher quality mean for area,speed,azimuth

I have some data that represents the area, speed(meters per second), and azimuth(rads) of a polygon. The objective is to determine the mean for each set of parameters. With that mean value, apply a ...
user avatar
2 votes
1 answer
59 views

Finding the modal hue of an image

As part of my first python project, I needed to know what the dominant hue of an image was. I started with finding the modal hue of the image, but the results seemed really odd in images with pale/...
user avatar
  • 163
3 votes
2 answers
75 views

Reformatting strings according to different properties with OO

I had to write a cycle that loops a log file and assigns a given status according to some logic. I didn't post the whole code but this is the script that bugs me the most... why? Well, first: I ...
user avatar
2 votes
0 answers
34 views

Interactive Gundam using only Matplotlib

The code below plots a background image (sky) and then a Gundam sprite using Matplotlib. It also creates 4 buttons with obvious purposes. The Gundam class stores 2 ...
user avatar
  • 1,142
2 votes
0 answers
42 views

Python data entry into excel based on equality check with dataframe

My objective is to enter/type in values into Excel cells if the column names and indices match between Excel and dataframe. So, my code does the below Gets the ID values from the dataframe for each ...
user avatar
  • 235
3 votes
0 answers
29 views

Arduino portenta H7 compatible message encryption and decryption

I am looking to build a message encryption/decription method that would allow messages to be encrypted in a timely fashion on board an Arduino Portenta H7, using as much of the onboard hardware ...
user avatar
  • 131
4 votes
2 answers
57 views

Search for providers of TV Shows

All my code is below. It uses an API to search for a show and then outputs the providers (like breaking bad is available on Netflix). The main aim of this application was to practice using APIs and ...
user avatar
  • 41
1 vote
1 answer
39 views

numpy mean azimuth with functools.reduce

From the left to the right column calculating the mean azimuth, and using that mean value to calculate the subsequent columns mean value data (azimuth radians) ...
user avatar
3 votes
2 answers
58 views

Find all indices where value of array changes

I try to solve the following problem using Python: Given a 1-dimensional numeric array arr, find all indices where the value of ...
user avatar
0 votes
2 answers
106 views

Python script for Web scraping

I wrote a Python script for Web scraping of a Website. Please review my code and suggest me any changes or make me aware of my blunders/mistakes?. I wrote the almost same script for other websites ...
user avatar
5 votes
4 answers
392 views

Coin flip streaks in Python

Below is the wording from the problem in Automate the Boring Stuff book. The bold text leads me to believe that I should be checking for a streak and not multiple streaks within each experiment of 100 ...
user avatar
  • 51
2 votes
1 answer
49 views

follow-up - Checking Nested Bracket Levels in Strings Programming Challenge

A follow-up to this question, this post improves on test case issues. To restate problem parameters, a given string S is considered closed if it: Has a matching ...
user avatar
  • 2,897
7 votes
0 answers
103 views

Making this python chess engine faster

I've implemented a chess engine using the python chess move generation library (which I assumed to be reasonably fast), and have implemented various optimisation techniques for search and move ...
user avatar
  • 81
0 votes
0 answers
37 views

Learning UML and OOP, trying to make a game in python. What do you think of this UML diagram?

I'm working on refactoring a simulation that i started writing in python / pygame. The gist is, there's buildings scattered around a map, and units carry items back and forth from said buildings. I ...
user avatar
  • 61
-1 votes
2 answers
61 views

Quantum Random Generator outputs pieces of PI [closed]

This is a curiosity as a follow up from Purely Random Numbers Generator ...
user avatar
  • 23
3 votes
2 answers
166 views

Programming Challenge - Capturing Bracket Levels

I don't have a formal description for this problem, but here are the parameters: Given a string S check that each opening bracket has a matching closing bracket. ...
user avatar
  • 2,897
0 votes
2 answers
72 views

Purely Random Numbers Generator

I think the best Random Number on the Planet is PI. I wrote a code that generates a list of pseudo-random numbers in Python. Then it treats this list as positions of digits in Pi and then outputs ...
user avatar
  • 23
3 votes
0 answers
31 views

Python Script that searches a corpus for most relevant results according to search terms

I am currently working on building a small search engine (if it can be called that) that allows users to search for relevant articles from a short list of other older websites that do not have search ...
user avatar
  • 31
2 votes
1 answer
81 views

Auto-fitting text into boxes in matplotlib

Task I tried to code a treemap function in matplotlib, and one of the challenges is auto-fitting text into boxes of different sizes in the treemap, similar to R's package ggfittext. My Code My ...
user avatar
  • 163
3 votes
1 answer
49 views

Making a list of shades and styles for plots

For a section of a much larger program that generates plots, I am creating a list of styles that I can pull from to create a consistent format from plot-to-plot. It works as follows I have a list of ...
user avatar
  • 33
2 votes
2 answers
85 views

Create csv file for each id value and write all data rows to csv with same id

I have a text file which is tab delimited: 1 324 2344 1 8372 1234 2 62 12 2 872 12111 2 1211 28736 3 87636 198272 The first &...
user avatar
  • 23
2 votes
1 answer
56 views

Searching for two integers root**pwr = integer(user's input)

Write a program that asks the user to enter an integer and prints two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. If no such pair of ...
user avatar
2 votes
2 answers
61 views

Programming Challenge: Python 3 DNS query resolver using socket

This is a DNS query resolver written in Python 3 using socket, I wrote it entirely by myself, it supports 8 primary DNS query types: A, NS, CNAME, SOA, PTR, MX, TXT,...
user avatar
2 votes
1 answer
130 views

Programming Challenge - Game Scoring

Can this solution be made more efficient? game_scoring.py ...
user avatar
  • 2,897
2 votes
0 answers
29 views

Weighted Union-Find class

For a final project I used a weighted union-find and decided to implement it in Python. I wrote it to be as general as possible so it's very portable. I do plan on looking into path compression to ...
user avatar
4 votes
0 answers
51 views

PyQt: Open a file dialog from a separate thread

Based on a question I asked on SO, I have come up with the following solution. As I am very new to Python Qt, I would like a review rather than just add it as an answer in SO. The code runs a script ...
user avatar
  • 141