Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

Filter by
Sorted by
Tagged with
-1
votes
0answers
19 views

Is The Logic Of This Program Correct? [closed]

I need to write a program that calculates ingredients for a recipe. Here is the question: A cookie recipe calls for the following ingredients. 1. 1.5 cup of sugar 2. 1 cup of butter 3. 2.75 cup of ...
1
vote
1answer
26 views

Day 3: Binary Diagnostic, part 1 (Advent of Code 2021)

Some notes that I thought would be worth mentioning up front: Advent of Code randomizes the input for each user, with the input format being 1,000 12-digit binary numbers delimited by newlines. I've ...
0
votes
1answer
47 views

Python - Calculating all combinations from arrays AND (arrays OR floats)

Context: My question comes from needing to iterate different np.arange arrays. The main motivation is to calculate all the possible combinations between the arrays, ...
4
votes
1answer
232 views

Inefficient Solution - Advent of Code 2021, Day 3, Part 1

My code is working but it is extremely long. So, I guess there is a way to make it shorter/more efficient. The problem solved here is from Advent of Code 2021, Day 3, Part 1: https://adventofcode.com/...
4
votes
1answer
38 views

API call scheduler for Python

My favourite 3rd party library isn't getting maintained so now I need to make my own library for interfacing with Riot Games' API. Epic. Problem is that there are rules, such as: 100 requests in 2 ...
2
votes
1answer
27 views

Read file from current path in Python

I had to write a custom function to load a yaml file from the current working directory. The function itself works and my intention was to write it in a pure fashion but my senior colleague told me ...
3
votes
3answers
659 views

Produce a list of every 1st, 3rd, and 5th Friday of each month in a date range

When fridays_135 is called, a list of dates between the start date and end date is produces by date_range. That list is then narrowed down to just the Friday dates and then grouped by month by ...
0
votes
1answer
64 views

Simple sort function

I am learning Python and for practice I have written this function which sorts a list. Can you please provide feedback on how I have structured it and what better ways could be there to write it for ...
3
votes
2answers
642 views

Magic ball 8 program

I was doing the Magic Ball 8 project (its task is to read a user's question and output a prediction) on Python and wrote the following code: ...
3
votes
3answers
87 views

Finding the next 9am/pm from now

I have some code that needs to return a datetime of the next 9am or 9pm, UTC. I've figured out some code to do this, but it feels unnecessarily complex to me. Is ...
4
votes
2answers
236 views

Remove matching lines from all files

I have written a Python3 program that looks for matching strings and removes them from files. ...
2
votes
0answers
40 views

Student report card management Python program

The program is designed to take data from a MySQL database, using mysql-connector-python, and print it as a table in Python using the texttable module. The program also plots charts based on the data ...
-3
votes
0answers
92 views

Making programming language

Code: ...
1
vote
1answer
71 views

Python IPv6 verifier, parser and converter

This is a simple Python 3 program that verifies whether a string is a valid IPv6 address or not, parses IPv6 address to its hexadecimal and decimal values, and converts an integer to IPv6 format. I am ...
2
votes
0answers
41 views

Naive Bayes spam classifier improvements

Could you please have a look at our naive bayes model. We look at a corpus of emails where an email is either spam or not. To classifiy we naively assume a bag of words and estimate prior ...
2
votes
1answer
83 views

Stop exam cheating using python: Part 2 - Argparse and config

Intro This is a spiritual successor to the question Stop cheating on home exams using python The details are not important, but I decided to reimplement everything using dataclasses. My script is now ...
1
vote
1answer
43 views

Printing reverse number triangle

I have to write a program in python that will take a number and print a right triangle attempting to use all numbers from 1 to that number. For example: ...
1
vote
1answer
73 views

Evaluating infix expression with brackets

My assignment was to write a function that computes the value of an expression written in infix notation. We assume that we are using the four classical arithmetic operations +, -, * and / and that ...
0
votes
0answers
20 views

view only INFO in console and save CRITICAL, ERROR, WARNING to log file

The following code log INFO in terminal and WARNING, ERROR or CRITICAL in file. my python file looks like: ...
4
votes
1answer
112 views

Return the biggest loss a client made from prices list

A hiring company gave me the following challenge: We want a function which accepts a very large list of prices (pricesLst) and returns the largest possible loss a ...
1
vote
1answer
36 views

When I try to re set up my code after failing in the game I cant get it to run the function without its own file being undefined [closed]

I know my code is ugly and unreadable. I originally had the game working without class functions but when I had to implement class function it all went downhill. TennisMaster.py ...
0
votes
0answers
39 views

Python 3 Table Improvements

(reposted from another forum, AoPS) I have made a "Table" data structure with fast mean, median, and mode calculations. To my knowledge there's no built-in function that does this. Here's my ...
0
votes
1answer
81 views

How to speed up the search for matching values in a second data frame in a line-by-line iteration over a first data frame?

I have a survey response dataframe for which each survey has a code: df ...
2
votes
1answer
79 views

Evaluating postfix expression on multidigit numbers

This is my solution for evaluating postfix expression using a stack. It does work on multidigit numbers, the problem I was struggling with last time. Now it works completely fine. This is the stack ...
2
votes
0answers
20 views

Make selected colours brighter in Blender

The problem: I am working with a set of objects in Blender with per-vertex colours. Each object has only two distinct colours. For all objects in a selection, I am choosing only the brighter of those ...
15
votes
5answers
1k views

Check whether a lowercase string has any character repetition

I got this HW question from my freshman year at college - "Create a python function to check whether a string containing only lowercase letters has any repetition in it". So, I did it a few ...
0
votes
0answers
12 views

Optimizing data processing of netCDF file

I am extracting/processing some data from a netCDF file. It is the first time I am processing the netCDF file. The data processing is super slow, and I would like to learn how to speed up the process. ...
2
votes
0answers
66 views

Web scraping articles using asyncio

I use asyncio to speed up web scraping. I collect only title, author, tags, datetime, total comments from list view from specific website. Also, i collect these from all pages. I would like to improve ...
2
votes
0answers
75 views

Python 3 simple PyQt6 GUI program that helps text processing

I am not sure how to accurately describe what this program does in just a few words, anyway this program is very simple and easy to use, what it does is very simple and it is good at it. Let me start ...
2
votes
0answers
73 views

Python Markov Chain based pseudoword generator

This is a Python 3 module that generates random pronounceable word-like strings based on Markov Chains. It has many modes, each mode conforms to the structures of dictionary words to a degree, the two ...
0
votes
0answers
48 views

Python Class for config file parameters

I have created the below script in which I'm trying to set up a class for handling a config file, but also defining some functions that I call from the class methods. Not sure if I'm following the ...
3
votes
3answers
410 views

Find the average score, given data in a table with labeled columns not in a fixed order

I was on Hacker Rank for the first time and there was a question that required to get the inputs from STDIN and use collections.namedtuple(). It was my first time ...
4
votes
1answer
65 views

Function to calculate the GC content variation in a sequence

I came across this BMC Genomics paper: Analysis of intra-genomic GC content homogeneity within prokaryotes And I implemented some Python functions to make this available as part of a personal project. ...
0
votes
0answers
47 views

Class to save the parameters of every function call

I wrote a function saving class which basically saves data of every function that's being called ...
6
votes
2answers
193 views

Container with most water, with pre-computation of possible bounds

Here's my attempt at leetcode's container with most water. Problem: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn ...
3
votes
1answer
99 views

Web scraping international trade data

I'm trying to scrape arrival data from this website. My script takes extremely long time to scrape the data. Is there any way I can speed up the scraping process? Here's my script: ...
1
vote
2answers
80 views

Generate a string that is not present in a list

For a college assignment, I was tasked with the following (excerpt from provided code file): Find one string of characters that is not present in the list. You are provided a function that loads the ...
0
votes
1answer
78 views

Python 3 weighted random choice function memoized version

I have written a function that randomly picks one element from a set with different probabilities for each element, anyway it takes a dictionary as argument, the keys of the dictionary are the choices ...
1
vote
2answers
48 views

easy to use control panel for minecraft rcon

I wrote a small program that connects to a minecraft rcon and provides an easy to use control panel. It is written in python 3.9 and uses the kivy module for the GUI. What could I improve in the code? ...
6
votes
1answer
116 views

Decorating __init__ for automatic attribute assignment: Safe and good practice?

I am currently trying to better my understanding of python and good coding practices and would really like some input on a question i have been thinking over for weeks now. I am currently working on ...
4
votes
2answers
189 views

i3 config file parser

So I am using i3 an Linux window manager to manage my windows. In addition this is run on a laptop that is frequently mounted to several output-displays. This is handled by the following lines in my ...
3
votes
0answers
53 views

Sudoku sequence solver for non-standard constraints

This script is designed to help solve sequences in Sudoku puzzles with variant constraints (ex: Thermometer, Renban, etc.). Summary The user specifies the constraints they want applied as well as the ...
2
votes
1answer
98 views

How to make my Collatz Conjecture code run a lot faster? (and even better, how do I implement it into multiple computers?) Python

I have been writing this piece of code for a while now, and I was wondering, is it possible to run this code multiple times on my pc? For example could I make the code solve all the numbers from 1 to ...
1
vote
0answers
80 views

Python functions to serialize nested data structures human readably

See Serializing (nested) data structures in a human-readable format for more details. In the last two days I have significantly improved my function, and wrote seven implementations of it. I have ...
1
vote
2answers
90 views

TextRPG written in python

I started to write a terminal based text RPG in python. Its mostly bug free now but I really want to know how I could improve my code and how to implement things better. I know it's a lot of code so I ...
0
votes
1answer
34 views

Making list of errors from file

So I have a file of errors, there default meanings and also it's hierarchy in terms of indentation ...
0
votes
3answers
70 views

Print greatest factor if it is same for both numbers

Take input n1 and n2 and check if they have the same greatest factor. If they do, print that factor. If they don't, print "No". example: input: 6 9 output: 3 input: 15 27 output: No ...
2
votes
2answers
81 views

Serializing (nested) data structures in a human-readable format with all bugs fixed

See Serializing (nested) data structures in a human-readable format for more details. This is the latest version, I have fixed all bugs and now this piece of code works completely as intended. And I ...
-1
votes
4answers
87 views

Python weighted choosing that works with very large numbers

I have written a function to choose randomly with weights from very large data sets in which the weight of elements can be several thousands. The input of the function is a flat ...

1
2 3 4 5
98