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
26 views

Why is following python code executing slowly?

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
30 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
15 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
51 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
571 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
41 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
72 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
43 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
20 views

Calculate of the average of time discounted values

Given the current table: ...
1
vote
0answers
21 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 ...
0
votes
0answers
34 views

Merge two Dataframe with condition

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
230 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
46 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
34 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
36 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
39 views

Create a histogram using JSON data in Python [closed]

I have data in JSON format. ...
2
votes
0answers
38 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
2answers
163 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, ...
-4
votes
0answers
40 views

Leap year in python brief code [closed]

Is this the correct way to calculate leap years in a range of [y,x) ? ...
6
votes
3answers
232 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 ...
0
votes
0answers
32 views

Building a Cricket Scoreboard from Python [closed]

So to check my Python knowledge I am building a cricket scoreboard in Python. My scoreboard could be able to can be used to store previous matches ' scores. A work in progress as of now. But as of now,...
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
71 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
1answer
42 views

Better way for successive conditional checks [closed]

I have a dataframe where i want to obtain the appropriate levels. I successively check each resolution range until the lowest hits. Seems a bit iffy to me, is there ...
-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
62 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 ...
0
votes
0answers
38 views

passing type value to a function on basic of values calculations [closed]

passing type value to a function on basic of values calculations. I am doing something like this to calculate and pass new values to funtion . ...
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
97 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
63 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
81 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 ...
0
votes
0answers
35 views

Solving a linear system with Gaussian Elimination

I decided to implement a solver for linear systems of equations based on the gaussian elimination and reduction to upper triangular form. The gaussian elimination is quite simple to implement but the ...
2
votes
2answers
65 views

Setting instance variable for salary bonus based on academic position

I have a class Scholar which is basically a teacher in a university. I have to calculate the yearly salary of a scholar instance where the formula is ...
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
0answers
42 views

Script to check a web service

I'm a Python novice. The system I'm using is called IBM Maximo Asset Management. In Maximo, we can write Python scripts that utilize Maximo's Java API/methods. So the script is technically a Jython ...
1
vote
1answer
69 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 ...
3
votes
0answers
45 views

Segment characters from license plate image according to regions with same height

I have (for example) the following license plate image: And I want to segment the characters. The code I have so far consists of me using cv2.MSER to detect ...
3
votes
1answer
50 views

Transposing an Excel sheet with pandas adding additional information for a different readability - Using Fake Pizzeria Data

The goal is to transpose the excel file that comes in the following form into this The code I created works properly, but I think it can be improved. I would also like to avoid using ...
0
votes
0answers
22 views

Possible to merge model method database calls?

I have an application using Django Rest Framework and a ListModelView for a model which I basically need to filter for in a MongoDB. The call for MongoDB is made in ...
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: ...
0
votes
0answers
16 views

Why is this MongoDB query so slow in comparison to python + in general?

There are 1.3M documents in my collection (5.0 and hosted directly on mongodb.com) and there is an index on "topic" and a combined index on "topic" and another field. However the ...
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 ...
0
votes
1answer
35 views

Is using except TypeError the right way to do this? [closed]

I have some code that uses a lambda to enhance the functionality. For backward compatibility reasons, this lambda can take one or two arguments. To handle these ...

1
2 3 4 5
283