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
5
votes
1answer
25 views

Chess game for my students

I teach programming, and I currently teach my class about inheritance, abstract classes, and mixins. I wrote this code as an example, and I want to be sure it is as good as possible before I release ...
-3
votes
0answers
7 views

How to add an interactive plot in Jupyter Notebook?

I have made a plot for the basic SIR model. I am satisfied with my plot, however, I would like to be able to have an interactive slider that tweaks my parameters beta and gamma. I would like both of ...
1
vote
0answers
14 views

Do I need to use inheritance and classes for my OOP webscraper?

I am currently writing python code that scrapes information from the web. I have to scrape several sites, but there a two types of procedures: Directly scrape from the website Download pdf and scrape ...
5
votes
3answers
6k views

Project Euler problems 1 and 2 in python

What do you think about my code? I am a beginner and just started doing some algorithmic exercises to sharpen up my python skills. Here is code for problem #1: ...
4
votes
3answers
78 views

Find the maximum price change over any 1 to 5 day rolling window

The code below solves the following task Find the maximum price change over any 1 to 5 day rolling window, over a 1000 day period. To be clear "any 1 to 5 day rolling window" means ...
1
vote
0answers
13 views

Converting a graph to a directed graph with order of the nodes defined by post-order traversal

Background: I'm implementing an algorithm from the paper Polygon Area Decomposition for Multiple-Robot Workspace Division and one of the steps is to represent a polygon as a graph. This is done by ...
1
vote
1answer
65 views

Best way to store the sum of all node depths?

To sum up all the nodes' depths in any given binary tree, I've written the following recursive algorithm: ...
2
votes
1answer
40 views

Parallel image segmentation

Follow up question Image processing using Python OOP library I want to use multiprocessing to analyze several images in parallel: ...
5
votes
1answer
22 views

Chemical reactor with UV light project in python

Introduction I'm new to python and made this code which computes the decay of sulphur dioxide (SO2) pollutant in a chemical reactor by ozone (O3) when it is hit by UV light. Code description Short ...
3
votes
1answer
44 views

Weather Forecast Web Application

I've made a Python Flask app and I have some questions about the structure of the main module (equivalent of index.py). Here is what it looks like: ...
-3
votes
0answers
18 views

Fix Hangman Game in Python [duplicate]

Can someone help me make a losing conditon in the function of " engine() " . i cant seem to make it because making an "else" loop causes the function to recheck it to every ...
6
votes
1answer
38 views

Red-Black Tree Implementation in Python

i'm wondering if there are better practices, and optimizations, i could make on my code, to do things easier/faster. I have added comments, in many places in the code, to make understanding easier. <...
5
votes
2answers
67 views

DNA Translator and Verifier (using BLAST)

Proteins are chains of amino acids. Amino acids are coded by codons, a sequence of 3 DNA/RNA molecules. DNA also has 3 open reading frames. This is basically the DNA sequence, but shift it by 1 (i.e. ...
1
vote
1answer
45 views

AVL Tree implementation Based on VisualGo

I have tried implementing an AVL Tree on my own, based on visualising it. But i'm unsure how many testcases it work with, and how efficient it is. Are there any ways to make it efficient, and compact? ...
3
votes
3answers
1k views

Binary Tree Sort Algorithm (Python)

A Binary Tree Sort is an algorithm that builds a binary search tree from the elements to be sorted, and then traverses the tree (in-order) so that the elements come out in sorted order. Average Case ...
2
votes
1answer
101 views

Calculator with PyQT5

Recently I started to learn Python and PyQT5. So here is my code for a calculator. Personally I don't like how the doMath() function is looking but I don't know ...
5
votes
1answer
91 views
+50

Create or update record via HTTP request

I have an external system that sends an HTTP request to a Jython script (in IBM's Maximo Asset Management platform). The Jython 2.7.0 script does this: Accepts an HTTP request: ...
3
votes
3answers
68 views

Password Generator Python

I decided to make a password generator to get more familiar with Python. I had to break up the code into two boxes due to weird Stack Exchange highlighting with the triple quotes. How would you ...
0
votes
1answer
41 views

Pandas filter dataframe on multiple columns wrt corresponding column values from another dataframe

I have a pandas dataframe, df1: a b c d e f 1 1 1 x 1 5 1 1 1 x 1 6 1 1 1 y 1 5 1 1 1 y 1 7 and another dataframe, ...
6
votes
2answers
1k views

Generating complementary DNA sequence

I am still relatively new to Python but I have been actively doing sample examples to try and get used to problem solving aspect of programming. With that said, I stumbled upon a question that asks ...
6
votes
2answers
275 views

My Graph Implementation In Python

I have implemented a graph based on theory, and I'd like some advice regarding best practice, and thoughts about what i didn't implement that would make it even more useful, along with ideas that are ...
3
votes
2answers
96 views

Factoring and solving a quadratic polynomial

So i code stuff for my fx-cg50 calculator's micropython as I'm an a level student and a python beginner, and i need help pointing out the bugs and some programming tips to further improve my code, and ...
6
votes
1answer
2k views

Parsing URLs in Pandas DataFrame

My client needs their Google AdWords destination URL query parsed and the values spell checked to eliminate any typos ("use" instead of "us", etc). I'm pulling the data using the AdWords API and ...
1
vote
1answer
32 views

Recursive Function to Produce Constrained List of Integer Partitions

I have modified a recursive function designed to print all the integer partitions of a positive integer to create a function that returns all partitions of the "number" parameter if they ...
2
votes
2answers
66 views

Make django, weasyprint code object oriented

Please ignore the comments in the code for the purpose of reviewing. I just require tips on using SOLID principles and how classes can be used in this code.Comments in the code are for mapping the ...
-3
votes
0answers
24 views
0
votes
0answers
16 views

Scraping (Selenium) [closed]

I can't seem to figure out how to click throw the load more until there is no more results. I've managed to scroll to the button in various ways. Can't seem to load to it and actually click. Help? <...
2
votes
1answer
27 views

SelectionSort Algorithm using Python

I am a rookie and I need help optimizing this SelectionSort() algorithm which I have tried using Python. ...
2
votes
1answer
69 views

Super greedy algorithm for Exact Three Cover

I had trouble solving instances of Exact Three Cover with 100 units in input C. All in a reasonable amount of time. Mainly because the problem is NP-complete. So I came up with an approximate solution ...
8
votes
2answers
568 views

Optimize function that returns length of a subarray

I did an exercise today on where the task is to write a function that returns the length of the longest subarray where the difference between the smallest and biggest value in the subarray is no more ...
5
votes
3answers
639 views

Coin Flip Streaks

The question is from Automate the Boring Stuff with Python and asks us to find the number of streaks of six heads or six tails that come up when a coin is tossed 100 times. Coin Flip Streaks: ...
3
votes
1answer
30 views

Count the number of riders in each category

I have a code to get riders from certain teams and calculate the number of riders in those teams in that category: ...
6
votes
4answers
1k views

Computing the item price and vat for a given pricing, order, and exchange rate

How can I improve the readability of the below function using a list comprehension? Also, is there a way to improve items() performance? ...
2
votes
0answers
14 views

Getting Graph and Block Animation to Run Smoothly Together

I have been working on some code that produces a live graphic of a graph and blocks moving. It works in theory but does not look like how I want. The animation runs very slow when showing both the ...
4
votes
1answer
36 views

Using Newton Method in a Neural Network/

I programmed a Neural Network to do binary classification in python, and during the backpropagation step I used Newton-Raphson's method for optimization. Any kind of feedback would be appreciated, but ...
1
vote
1answer
16 views

Check that elements in list follow a specified date-format schema and are not null/na/nan

I'm practicing some data-analysis and I'm currently checking the integrity of my data. The elements that do not follow my date-schema, should be funneled to a new separate list so I can work on ...
2
votes
1answer
139 views

Smart Tic Tac Toe, a reinforcement learning approach

I'm currently familiarizing myself with reinforcement learning (RL). For convenience, instead of manually entering coordinates in the terminal, I created a very simple UI for testing trained agents ...
7
votes
0answers
54 views

Calculating a unique count within a rolling time window

I have a Pandas DataFrame that contains a row per member per day, expressing member interaction with a website. Members interact only on some days, each member is identified with an ID. Here is a ...
3
votes
4answers
131 views

Short code in Python Rock Paper Scissors

I am studying and practicing Python; this is my Rock-Paper-Scissors game I've built from scratch. I saw this task is for beginners. When writing this in all the examples I saw dozens of lines of code ...
2
votes
0answers
26 views

Web scraper for driver's license test times

I have created a small selenium script that checks for available times to write a test for a drivers license. The program runs every minute and takes approx 50 seconds to run. I have noticed that it's ...
6
votes
2answers
75 views

Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
0
votes
1answer
102 views

changing from function based view to class based view in Django [closed]

This is my attempt to convert my password reset function based view to a class based view. Please suggest improvements. This is my function based view ...
5
votes
0answers
55 views

K nearest neighbours algorithm

Here is a project that I worked on for a few days in June 2020. Since the algorithm is extremely slow, I looked into methods in order to parallelize operations but did not obtain any satisfactory ...
1
vote
2answers
39 views

Hex boardgame with fast random rollouts (OpenAI gym framework)

I implemented the boardgame Hex using the OpenAI gym framework with the aim of building a bot/AI player that can learn through self-play and expert iteration (details Note: not my paper; I am merely ...
3
votes
1answer
38 views

Class or not in Page Scraper (Python BeautifulSoup)

I am trying to figure out whether the below is better than just having a raw script or just a script with functions. ...
3
votes
2answers
77 views

Mini guessing-game

I am a beginner programmer and I would like to improve in coding and develop my skills. That is why I am asking this question, what should I focus on improving in this code ? ...
2
votes
1answer
42 views

follow up: Blackjack with card representation visuals

This is a follow-up to my original post of Blackjack with card representation visuals I was given some very helpful advice by @Reinderien and @Linny which I greatly appreciate. I have done my best to ...
12
votes
2answers
542 views

Blackjack with card representation visuals

To try and practice OOP, I've heard making a blackjack game can be really helpful; which it has been. I don't know how 'advanced' an implementation this is; but it has all the standard features, like ...
-2
votes
0answers
49 views

How to rewrite this piece of code? [closed]

I have the next piece of code. It's handler in python3, aiohttp framework. This code make post request to redis. But it looks like awful, how to fix style of this code? ...

1
2 3 4 5
249