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
0
votes
1answer
45 views

Shopping list using Python 3

In this python program, I used lists and control flow to allow users to add items to a shopping list and display the list. I need advice on my code in terms of (architecture, risks, opportunities, ...
3
votes
2answers
411 views

The cleanest way to print the max value and its key from a dictionary

I'm getting the highest value and its respective from a dictionary and printing it out for the user. Even though it's working, I'm wondering if I'm doing it in the cleanest way. Here it is: ...
3
votes
1answer
30 views

Ticketing program using Python 3

In this python program, I built a ticketing system with functionality such as keeping track of tickets sold and error handling in case there are any invalid inputs. I need advice on my code in terms ...
0
votes
0answers
45 views

Object-oriented poker game

To give a short contextual description: It is a poker game. I plan to add "cards" and a "pot"-object later on and then learn event-driven programming so that I can add a GUI. ...
5
votes
1answer
451 views

Analyzing average movie budgets using Python 3

This python program analyzes movie data by finding the average budget of films in a data set - it also identifies films that exceed the average budget calculated. I need advice on my code in terms of (...
-1
votes
0answers
10 views

Print data in file in ordered list [closed]

I'm practicing for my upcoming test and I trying to figure out how to print data inside the FILE. accounts.txt ...
4
votes
1answer
81 views

Rock, paper and scissors

I started reading a book about python two days ago and today I wrote my first code. It's supposed to be a rock, paper, scissors game and from the tests I've done so far it works quite well. However ...
0
votes
0answers
14 views

Python script to replace GitHub password with tokens

I manage a fleet of IoT devices. As for now, GitHub announced that the username-password authentication would be deprecative soon, so I have to change the password on each device to the GitHub access ...
2
votes
2answers
74 views

return the sum of the squares that is equal to n²

I'm struggling to solve this Kata. My code works but I can't pass because it's timing out. I have googled it and even tried other people's code but still doesn't pass. Any suggestion on how can I make ...
6
votes
2answers
383 views

Named tuple with less-than operator

I have the following implementation for the __lt__. Could you please check if it's okay to compare objects like that? ...
0
votes
1answer
28 views

Tkinter music player

I tried making a music player with tkinter in python but there's an error about module not callable but I'm not able to fix it. Can someone help? ...
0
votes
0answers
23 views

Multiple filtering of rows based on 1 single column [closed]

Sample.csv timelines I need to modify this piece of code in (the attached sample.csv file) where I can conditionally select more rows just between the values based on a timeline. I have a total of 38-...
3
votes
1answer
56 views

Java i/o speed less than python i/o while printing an array

Motivation: I was solving an array based i/o problem and encountered Time Limit Errors, it was later found that the code for java ran roughly 10x slower than the ...
3
votes
1answer
53 views

Merging pages together into an append log

Situation I'm scraping data from a paginated list on a website to be sent out as notifications. For the most part we'll only need to scape the first page and handle additions, deletions and duplicates....
2
votes
1answer
64 views
+50

a prototype of finding the (almost) best learning rate and initial weights so that a perceptron converges with the minimal iteration

First of all, I chose the nearest data points/training examples ...
-2
votes
0answers
18 views

Why does this code returns the error: [closed]

do you guys know what´s wrong with this code? it returns: cannot unpack non-iterable NoneType object and if i erase the bottom line, the code runs but if i print e_lib or e_tot it returns me: is not ...
-1
votes
1answer
25 views

Thread-safe LRU cache in Python

I've written a simple LRU cache class and I am trying to make it thread-safe. My thoughts are that I just need to wrap the code that updates the ordered dict in a lock so that if any thread is writing ...
3
votes
1answer
43 views

Simple Python Recursive Web Scraper

I tried to make a simple recursive web scraper using Python. My idea was to grab all the links, titles and tag names. Website: https://lifebridgecapital.com/podcast/ Course of Action: Grab all the ...
3
votes
1answer
49 views

Particle swarm algorithm with multiple threads

I wrote a simple multitthreading program which does particle swarm optimization. Optimization itself and some corresponding functions were taken from https://nathanrooy.github.io/posts/2016-08-17/...
0
votes
1answer
43 views

Comparing global sales of video game publishers

I am trying to create a function which can visualize(compare) two items of 'Platform', 'Genre' and 'Publisher' according to the 'Global_Sales' in different 'Year'. The DataFarame looks like: Code: <...
7
votes
1answer
295 views

Genetic algorithm to guess coefficient of a polynomial

I have tried to code a genetic algorithm to guess the coefficients of a degree 4 polynomial. The information initially provided is values of y = f(x) for different x using the original polynomial. I ...
8
votes
2answers
83 views

Representing Tic-Tac-Toe using a binary BitBoard

So I have been learning more about binary numbers lately, particularly in related to describing a gamestate. While perhaps chess is the most natural candidate I wanted to start of with something ...
1
vote
0answers
36 views

Computing the angle between two vectors (vectorized) for small angles and with few copies

I am implementing a function that computes the angle between two vectors when given two n-dimensional arrays and an axis along which to operate. I want to do this with as few copies as possible, and ...
3
votes
4answers
344 views

Converting a string to an array of integers

I am dealing with a string draw_result that can be in one of the following formats: ...
3
votes
0answers
44 views

Speed Up API Requests & Overall Python Code

I'm not asking for help solving a problem but rather asking for help for possible ways to improve the speed of my program. Essentially what this does is: Tracks market data by pulling the data from ...
1
vote
1answer
38 views

Tic Tac Toe (new draft)

I have implemented suggestion and created new draft of the Tic Tac Toe program. Please review and let me know where I can improve. ...
3
votes
1answer
54 views

python - Connect 4 Terminal Game

I developed a python Connect 4 game that only uses sys & numpy everything else is regular python! All I'm requesting is a stronger code. This is what I made: <...
2
votes
0answers
72 views

Looping through keywords and multiple pages in Selenium

This is a follow-up of my question over here. I adopted @Reinderien's suggested script to a second website below: fudan.py ...
5
votes
2answers
51 views

Count *.plot files in certain directories on network filesystems

First of all, I am playing around with python for about a week tops. Absolute beginner here. My story: I work as an IT administrator so I am familiar with eg. PS on a very basic level. I actually got ...
1
vote
1answer
68 views

Tic Tac Toe program

I have created a simple Tic-Tac-Toe program. Can someone please review it and let me know where I can improve. Here we can play against computer. Program start by putting 'X' at the center that is at ...
1
vote
0answers
48 views

How to Better Parse CSV file with Pandas

I am working on a CSV data Sheet and want to parse and filter the data out it, While working on a code I found a similar code someone has asked on SO POST there and ...
-2
votes
0answers
24 views

How do I fix the Python calculator to make it only perform 3 calculations, then prints “THE END” [closed]

This code continuously asks to input numbers. I want it to only ask 3 times, then it prints "THE END", meaning that the calculator is capped at 3 calculations ...
3
votes
1answer
115 views

Reinventing BGR to Grayscale OpenCV convert function in Python

For academic purposes I want to reinvent Blue Green Red to Grayscale function in Python. I am new to Python so I believe my code below can still be optimized. ...
1
vote
1answer
39 views

Discord.py pages for a leaderboard

So I've got a Discord bot that will load information about a user's personal charts and display it to them, and one of the commands is to get their leaderboard and show them the most successful songs ...
2
votes
1answer
39 views

Python Text-Based Hangman Game

I have just written a hangman game in Python for a school project. It reads in a list of words from a text file, and graphics from another text file. For each word, the program asks keeps asking for ...
0
votes
1answer
57 views

sorting list using selection sort algorithm

Sorted List value using algorithm selection sort. Can you please review and let me know where I can improve. ...
1
vote
1answer
55 views

How to make use of a class of descriptors to save code and other issues

This is a follow-up to my question over here. Having worked through most of the issues highlighted by @Reinderien in his detailed answer, I somehow got the code to work... Some quick observations: <...
3
votes
2answers
69 views

CLI-Client for interacting with daemon

I have a daemon which I am able to interact with through a cli-client. The daemon will perform some tasks in future e.g. monitoring the rate at which files are added to a directory. Right now when I ...
3
votes
1answer
58 views

python - Tetris Game

I have developed a game that allows you to play a full game of Tetris. I haven't really been getting the runs and plays. So I have a request for your reading... Can you possibly give me ideas and or ...
4
votes
2answers
147 views

Find all subranges of consecutive values in an array

I was looking at a dataset with a year column. I wanted all the years with matching a particular event. I then get a list of years which is not easy to read: ...
3
votes
1answer
63 views

Getting xpath indices to count forward to preserve table structure

Scraping tables from the web get complicated when there are 2 or more values in a cell. In order to preserve the table structure, I have devised a way to count the row-number index of its xpath, ...
3
votes
2answers
101 views

Structural Pattern Matching syntax to match a value in a list

I was looking into Python 3.10's Structural Pattern Matching syntax, and I want to refactor one of my code that uses if-else, using structural pattern matching. My ...
0
votes
2answers
70 views

Is my custom operator for sorting in python correct?

I want to sort object list named schedules according to arrivalT. if arrivalT is equal, I want to sort according to burst, if arrivalT and bursT both equal I want to sort according to id. Is my custom ...
7
votes
2answers
86 views

Python script for alerting disk usage and take action if needed

I am running an IoT fleet, and the need for checking the empty disk usage space has increased. So I am using the following python code. In addition to best practices, efficiency, readability, pythonic,...
1
vote
0answers
17 views

Building a generic WebSocket component in Python

I have the following working code for a generic WebSocket component: ...
3
votes
1answer
38 views

3d Cistercian numbers mini game (MatPlotLib), inputting similar xyz coordinates 50 times, how to streamline?

Dear coding black belts, My code is working but seems clunky. Take a random number from 1 to 99,999 Display it in 3D in a modified version of the Cistercian numerals from 13th century monks (adding ...
2
votes
1answer
45 views

Find the most similar pair of rows from a table

I have a list of n cities and hourly weather prediction for each one of them for h hours. I'm writing a script to find a pair of ...
6
votes
4answers
553 views

Monty Hall simulation - OOP

I mainly write code for data analysis so don't think about or use OOP at all on the day job. I thought I'd have a go at a simple Monty Hall simulation in an object-oriented style to figure out how it ...
3
votes
2answers
60 views

Python 3 approximate pi using 9 algorithms

Note: this script requires gmpy2, if you are using Python 3.9.5 x64 on Windows 10 21H1 like me, then you need to download the pre-built ...
2
votes
1answer
21 views

API design of library for argument inspection & filtering

I wrote the following Python library for getting a callable's argument names, testing whether a callable takes an argument with a given name, and filtering a dict ...

1
2 3 4 5
274