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
-1
votes
0answers
13 views

Is it ok to use truthy / falsey values for logical conditions in python with lists and strings? [closed]

For the last few months, moving from a non-pythonic language, trying to ensure that we use best practices in Python. What is truthy and what is falsey for different data types is well known in Python, ...
4
votes
2answers
118 views

Simple Calculator Python

Hi I am new to python and I have written a simple calculator, I would like to ask if the code is written well or if anyone has any tips on how to write it better. ...
-1
votes
0answers
20 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
27 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
49 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
235 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
41 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 ...
7
votes
3answers
282 views

Draw a 2d graph using slashes

Given a list of integers a 2D graph has to be plotted taking 1st, 3rd, 5th, ... numbers as upward slope and 2nd, 4th, ... numbers as downward slope. I have used a Python list to do it. Is there any ...
0
votes
0answers
31 views

Object Oriented Routing using Python's FastAPI

I created a BaseRoute class route handling. The BaseRoute class takes the following parameters: ...
3
votes
1answer
66 views

Generate and display usernames

Everything currently works exactly as requested by the instructor, I've included as much possible commented documentation as I can think of to make it easier for people to see what the required ...
4
votes
1answer
94 views

Design a pattern using python

I want to print the below pattern * * * * * * * * * * * * * * * My logic written ...
4
votes
1answer
51 views

Find the mean magnitude of values inside unit circle

I'm fairly new to Python and am exploring how to fix functions and make code 'more effective and readable'. As a first step, I would want to try to make shorter snippets of code here - for example by ...
1
vote
1answer
32 views

Simple Rock Paper Scissors game in Python

I am trying to write a simple rock paper scissors game in pycharm using classes and pygame. So far, I have not incorporated pygame yet. My idea is to import images that change in regards to the user's ...
1
vote
0answers
31 views

How can I optimise my recursive backtracking sudoku algorithm?

I've tried optimising my program by removing invalid values for possible spaces instead of searching from 1-9, and by choosing values with the lowest number of empty spaces in its row and column, but ...
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
661 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
0answers
56 views

String search using Rabin-Karp algorithm

I am trying to solve a needle in haystack using Rabin-Karp algorithm, but for large inputs my code takes way too long time. Here is the part which apparently is too slow: ...
0
votes
2answers
48 views

Python function for finding if all substrings exist in a string in sequence

I want to find if all of a list of substrings exist in a string, in the correct order (with or without spaces between them), it seems to be a good use for regex. I think I need to build a regex ...
0
votes
0answers
18 views

Command-line sentence-by-sentence EPUB reader in Python

This is a command line application which displays the text of an EPUB one sentence at a time. I am going to make it more robust, including: make the segmentation more accurate, because it currently ...
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: ...
0
votes
1answer
45 views

Absolute Permutation | Hacker Rank: Any way to make this python code faster without changing it's whole logic?

https://www.hackerrank.com/challenges/absolute-permutation/problem I know that if you work out the math and logic first, the algorithm can be simplified greatly (shifting indices), but is that the ...
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 ...
1
vote
1answer
48 views

best way to get data from dict

I have a function general_statistics that takes a dict as input and get the wanted information. the function is working without any problem, but I want to know if I ...
0
votes
0answers
22 views

Calculate of the average of time discounted values

Given the current table: ...
1
vote
0answers
22 views

find max value in islands defined by other vector

I have a vector of values vals, a same-dimension vector of frequencies freqs, and a set of frequency values ...
-1
votes
0answers
38 views

Merge two Dataframe with condition [closed]

I have 2 datafarme And need result, date of datefarme 2 between date of dataframe 1 result = A of datefarme 2 add in datafarme 1 ...
4
votes
2answers
237 views

Remove matching lines from all files

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

Higher lower game

I'm currently learning python with an udemy course. I wrote this code, which is meant to be a higher lower game, where the second answer always stays. As far as i tested it my code is working fine, ...
1
vote
0answers
36 views

Mean, median and mode GUI

This program takes x numbers and displays the mean, median and mode. My goal here was to use classes and class properties the best i could to make the code shorter (honestly i may have just made it ...
-1
votes
0answers
27 views

What would be a recommended data structure for a set of baking conversions? [closed]

I am working on a Python package for converting baking recipes. Ideally, the recipe is simply stored as a CSV file read in by the package. Given the recipe can be imperial or metric units of ...
3
votes
1answer
37 views

Path of a particle in a non-uniform B field

I have completed my project which simulates the path of a particle trapped in a device known as a magnetic mirror. I would like your thoughts and improvements on my implementation. Here is the code: <...
-3
votes
0answers
42 views

Create a histogram using JSON data in Python [closed]

I have data in JSON format. ...
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 ...
2
votes
2answers
165 views

Improving the Conway's Game of Life Code With Functions in Python

This query is a part of Conway’s game of life. Currently, this program takes about 70 lines of code in Python to return the functionality of the game, which can be simplified to fewer lines of code ...
-4
votes
0answers
29 views

Python program to convert decimal to binary [closed]

I wrote a program with Python that converts decimal positive numbers to binary and puts the result in a list. I have a problem with decimal 0 because the result I get is ...
-2
votes
0answers
25 views

Minimize sum of array after performing K operations(Python) [closed]

Given an array \$a\$ of integers, find minimum sum obtained after performing \$K\$ operations. In this context operation involves choosing an element a[i], multiply it by \$2\$, at the same time, ...
6
votes
3answers
235 views

Count the numbers in a range in which the sum of the odds digits have the same parity of the evens one

As already written in the title I want to count the numbers in the range (x+1, y) where x and y are integers, in which the sum of the digits in odd places have the same parity of the ones in even ...
1
vote
0answers
38 views

Pokédex by a Python novice

This is my first real personal application and I'm just looking for some outside feedback. Completely built in Python, this is a Pokédex for the Pokémon Mystery Dungeon series. I hope to eventually ...
2
votes
1answer
88 views

Getting values from a given level of a nested collection

This question is a supplement to my previous question: Counting 'absolute' nesting levels of an iterable. I would like to expand functionality of counting nests in order to get values from given nest. ...
1
vote
1answer
73 views

HackerRank - Climbing the Leaderboard: I don't understand why my code is exceeding the time limit

Climbing the Leaderboard An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this: The player with ...
6
votes
2answers
111 views

Counting 'absolute' nesting levels of an iterable

I need to write a function to count numbers of nests in an iterable. I reached my goal but wondering if there's any more neat/faster solution (maybe even a library or so?). Besides I'm afraid that my ...
0
votes
1answer
58 views

Possible memory leak in Python script which plays sound while holding down a button

I am working with Raspberry Pi and I made this little Python script that plays sound while you hold down a button and it keeps repeating while you hold it. and no matter when you stopped holding ...
-1
votes
0answers
23 views

Size Constrained Integer Partitions of a Given Number [closed]

As a smaller part of a programming challenge, I am writing a function in Python that takes two parameters, a given number and a size constraint. The function yields a generator that produces the ...
0
votes
0answers
32 views

One-way chat which encode messages, this is the server side

Alright, this is one of my first real projects in python, it's basically a one-way chat where the server sends away an encoded message. The logic of it is pretty simple and I know there is some ...
1
vote
1answer
66 views

DNA Challenge from CS50

Added the problem link below and my implementation of it. Took me a few hours to program. I have added comments to explain my thought process. Problem Link Goal - To implement a program that ...
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 ...
3
votes
2answers
106 views

Python TIC TAC TOE Project

I just joined here. I have been doing python for a couple of weeks and I would like for some experienced programmers to review my code. I made this for a school project and I am proud of it. The code ...
1
vote
1answer
64 views

Web Scraping DOL with Selenium

This is my code to extract data from the DOL website for a project I'm doing for my portfolio. The code does extract all of the data that I need, however it runs really slowly. I think it took like 15 ...
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
2 3 4 5
284