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
0answers
7 views

Chess using pygame

I just completed my second python project which is a chess game. At the moment I have included a mechanism for pieces to lock onto a square based on the nearest square when moved. And I have ...
2
votes
0answers
8 views

Python script to collect NWS gridpoint forecast data (JSON) and push it into MariaDB

This script is my first-ever attempt at writing anything in python. Though I have an electrical engineering background and therefore got a little programming education in college, it was fairly ...
2
votes
1answer
32 views

Python Math Quiz

In the process of trying to learn python, and also help my daughter with some elementary math practice over the summer, I'm trying to write a simple math quiz which will reinforce what she learned ...
0
votes
0answers
15 views

Filtering a file name based on Ignore pattern in Python [closed]

I have a definition of copy_tree where, I need to ignore files if they end with txt. I need to check if the non-directory file matches the ignore pattern being sent. How do I achieve that? ...
0
votes
0answers
6 views

How to avoid retracing in tensorflow when predicting scores for inputs with different sizes

I use the following code in order to assess the quality of an audio, which is based on this original-project: MOSNet. I call compute_mosnet_score() in a loop with a ...
3
votes
2answers
39 views

Q: Paying Debt Off a Year, MIT edX 6.001 U2/PS2/P1

Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the credit card company each month. The following variables contain ...
3
votes
1answer
30 views

Python PyQt6 populate QTreeWidget with a list of named tuples

This is a Python 3.9 script that pulls data from a MySQL database and converts it to a list of named tuples and then passing it to PyQt6.QTreeWidget. It has to be a ...
3
votes
1answer
44 views

Python script that makes ngrams

This is a Python script that generates ngrams using a set of rules of what letters can follow a letter stored in a dictionary. The output is then preliminarily processed using another script, then it ...
3
votes
1answer
74 views

HTML Paragraph Identifier

I have various texts that are inconsistent in how paragraphs are formatted. Some texts use the <P> </P> tags to specify a paragraph, while others use ...
4
votes
1answer
33 views

K Inverse Pairs Array - Brute Force

For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and ...
0
votes
0answers
21 views

Python text based game: Adding to inventory from a dictionary [closed]

I am trying to add items to the players inventory from a dictionary. However, when I add the first item to the dictionary, the program stops repeating the while loop. Can anyone help with this or give ...
9
votes
3answers
384 views

Asynchronously scrape fabric information

This is my first asyncio/aiohttp web scraper. I am trying to wrap my head around Python's asyncio/aiohttp libs these days and I am not sure if I fully understand it or not yet. So I'd like have some ...
3
votes
1answer
65 views

How to handle configuration from a config file and global variables transparently in python?

This is how I handle configuration in my python code, currently, but I guess it might look magic to people, and it is cumbersome to code. How can this be improved? Are there better solutions? The ...
6
votes
1answer
78 views

Count the number of saleable pairs of items

I want to optimize my code for following question: A company sells dumbbells in pairs. These are weights for exercising. They receive a shipment of dumbbells weighing anywhere from 1 unit up to a ...
0
votes
0answers
10 views

Debugging problem with dimension shapes in CapsNet and Routing setup [closed]

I'm learning about CapsNet (Ref. :Paper) and inspired by this GH. considering I tried to simplify entries in the Routing algorithm, I get the following errors which ...
1
vote
1answer
93 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, ...
7
votes
2answers
930 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
2answers
71 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 ...
2
votes
2answers
81 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. ...
6
votes
1answer
519 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 (...
0
votes
0answers
12 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
91 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
17 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
79 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 ...
7
votes
2answers
390 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
31 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
59 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
58 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
93 views

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
19 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
47 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
46 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
298 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
92 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
43 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
347 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
40 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
55 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: <...
3
votes
1answer
117 views
+50

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
71 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
50 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 ...
3
votes
1answer
117 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
41 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
40 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
2 3 4 5
274