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
4
votes
0answers
21 views

Code optimisation: Converting dataframe to numpy's ndarray

I am working with a dataframe of over 21M rows. ...
1
vote
0answers
22 views

Looking cleaner code of Python Combining Image with PIL

Please review and help me write better codes. Combining Pictures We can use a conditional to copy just the non-white pixels from one picture to another picture. We can take this tiny image of the ...
6
votes
0answers
27 views

A program that calculates how dense each character appears when printed

I wanted to know how "dark" each character is when printed. I thought that this may be useful when doing ASCII-art to help with shading. I decided to write a program to objectively measure ...
7
votes
0answers
29 views

A Server and Client Chatroom Using Sockets and Threading

I made a chatroom with a server and client python files, using Sockets and Threading as a project. I'm interested to acquire ...
4
votes
0answers
26 views

Instantiate multiple classes in another class, invoke method from multiple classes

The goal here is to pull all alerts from a single iterable: obj = Alerts(db, args) for alert in obj.alerts() pass Now, I need to add a few more sources and I'm ...
6
votes
2answers
52 views

Simple python string to list parser

So I came across this question on SO and I felt like it would be a cool thing to try and write a parser for since I always wanted to try it. So I present to you: My first time writing a parser. It ...
2
votes
1answer
38 views

Filtering out, a list of games, based on their followers

so I am playing with Rawg.io 's API. U can sort their game list by their release date, however there are just too many games. In their website, there's an option called "Popular only", which ...
8
votes
1answer
969 views

League of Legends Summoner Analysis

This program will ask for user to insert summoner and base from the last 20 games of said summoner, it will give avg stats and see if good or not by wins in last 20 games(a simple grading system). <...
2
votes
0answers
40 views

Get the value of the precedent day in a pivot table

I have a pivot table of approximately 2 millions lines coming from a dataframe with the same structure as below: ...
3
votes
0answers
26 views

Microservice for scraping images with celery

I made a project, that scrapes images asynchronously and saves them in container. I have access to them through volume. Scrapy finds images on given web page. Any tips will be good. But first I would ...
1
vote
1answer
59 views

Reduce one for loop to decrease time complexity

I'm using NumPy to find out langrage polynomial interpolation. I'm using 2 for loop to find out langrage polynomial, but I want to reduce 2nd for loop so that my code time complexity can be less. Can ...
5
votes
1answer
46 views

Parse bed file with Pandas

For the sections between count=1s and the start and end; combine overlapping positions and output the median of the counts. Input ...
14
votes
3answers
2k views

Implementations and analysis of my python login system (~80 lines)

I wrote this login system in the evening and i would like to know what should I fix / change, if should I use classes and, about readability, if this code is OK. I'm a begginer in coding so made this ...
1
vote
0answers
40 views

Integrating web scraping code into loop

Background: I have systematically written code segments that scape a recipe website for certain recipe stats of information including: Ingredients list Method / Instructions Prep time Cook time Yield ...
13
votes
5answers
2k views

Finding an element without pair in a list O(n**2)

I'm practicing algorithms, and I just can not come up with a faster solution to this problem, but I'm not hitting the benchmark. Problem: In a large list of large integers, I must find the one element,...
4
votes
2answers
354 views

Simple console calculator in python

I am new to python, I made a calculator but I need to make it calculating unlimited numbers and to shorten the code more, how can I improve it? Any help is appreciated. ...
-4
votes
0answers
18 views

I can't figure out why MongoDB connects but does not retrieve data. I'm using Python with pymongo [closed]

i'm brand new to Python and MongoDB and currently trying to figure out how to retrieve data from a database. When running the code I get the Mongo is connected ...
-6
votes
0answers
39 views

how can i make a beter code in python? [closed]

it is my code for problems five of euler project where is my wrong and how can i make a beter code please make my code true ...
2
votes
1answer
44 views

Load multiple worksheets from Excel file to multiple DataFrames

The spreadsheet can be found just above the references section at this link. https://www.sciencedirect.com/science/article/pii/S1872497316301429 It's a publication for STR DNA locus frequencies to ...
4
votes
2answers
59 views

Optimizing performance of randomly generated pygame maze game

I made a random maze generator that is also playable. The performance is crap and I'd like to improve it. I'll be working on this for a few more days to make it run better myself, but just thought I'd ...
1
vote
1answer
45 views

nth Factorial of n 1s in a row

In what way can I improve this? Be that performance, readability, etc. I'm thinking implementing NumPy would improve performance. Usage: Calculate* the nth factorial of n 1s in a row. *No need for a ...
2
votes
0answers
20 views

Ubuntu GTK+ 3 desktop app, made with Python library PyGObject

I just created my first GTK+ 3 app with Python using PyGObject. It is very nice to be able to make GTK applications using Python, as I love that language. I'm not completely sure if the way I designed ...
-4
votes
0answers
35 views

HackerRank Apples(Python) [closed]

There are M Women sitting on the chair in a row. Every woman has a number assigned to it. Person A is distributing the apples to those women with following conditions. Each woman has at least one ...
6
votes
1answer
239 views

Optimizing Efficiency in a Stack

I'm solving a problem on HackerRank where I'm required to implement a simple stack. It's passing all the tests except for the last 4 where it fails due to surpassing the time constraint of 10s. ...
3
votes
0answers
65 views

Providing a connection pool

I need some opinions about method naming and single responsibility principle. First of all, let's talk about method naming. The class below was created to provide a connection pool and whenever a pool ...
6
votes
1answer
69 views

Putting millions of items in a QTreeView

I have a list of 2,888,991 channel objects. Each object has a name and a sample rate. I am trying to put them into a QTreeView. Each channel name is split on ':' '-' and '_'. If the name is H1:IOP-...
3
votes
1answer
29 views

Check if an inputted string is in the right format for a valid rgb color

It is a practice from the site edabit.com and you have to check if the input is valid. That is the original task: Given an RGB(A) CSS color, determine whether its format is valid or not. Create a ...
5
votes
0answers
79 views

Python version of Clean Code book example

I started reading Robert Martin's Clean Code. I'm trying to "translate" all his examples into Python, so I can understand them better since my domain on Python is greater than on Java. ...
4
votes
1answer
25 views

Transforming UCI-move into bitboard, chess

I want to transform a UCI-move into bitboard. for example a2a3 -> 32768, 8388608 I need to assign [7,6,...,0] to [a,b,...,h] so that for each letter i have the assigned number(n) to calculate 2^n ...
-4
votes
0answers
27 views

Creating Python dictionary from csv with lists as values [closed]

I have a large .csv file of coordinates similar to this: I am trying to loop through it to create a dictionary where each unique value for "Index" is a key, and the corresponding value is a ...
1
vote
0answers
37 views

A Tabbed calculator in python with tkinter

For learning purposes, I have written a small calculator app on Python, tkinter. I want to check if my design is on best practices for OOP, And seek advice on Nested functions For easy readability, I ...
4
votes
1answer
73 views

Highlighting partitions in distinct color

Given: G is an arbitrary graph partitions is a list of its edges divided into (in this case) 3 sets. Color generation: Its ...
9
votes
4answers
482 views

Hangman game implemented in Python

I'd like to know how to improve this code because I think that the main_func is too big and I can not split it into other functions or classes. Also, I want to know ...
1
vote
0answers
27 views

Simple food inventory manager in Python3

I've made a simple food inventory manager in Python3 Please tell me what can be improved GitHub ...
5
votes
2answers
116 views

Can it be shorter?: DNA Sequence Analyzer from CS50 written in Python

This is my first time requesting a code review. This is code I wrote in Python to create a DNA sequence analyzer. This is for the Harvard CS50 course. I was really hoping to get some constructive ...
0
votes
0answers
5 views

code into def function [migrated]

I'm brand new in Python and trying to solve one of my exercises: Below is a code describing growth of money, which started at $100, and which grows over time at a rate of 3% per year. The balance at ...
7
votes
2answers
562 views

This python code converts integers to strings and strings to ints without the inbuilt functions “int()” and “str()”

It is my solution from a challange from edabit.com named "Drunken Python". Thats the task: You need to create two functions to substitute str() and int(). A function called int_to_str() that ...
-5
votes
0answers
23 views

8 Puzzle problem using BFS in python [closed]

i want to apply 8 puzzle problem in python using BFS algorithm in simplest way. please somebody help me. i just write the main class but i cant go further. ...
9
votes
4answers
3k views

Player data collection program

I'm working on a program that uses the RIOT API League of Legends for collecting player data and calculate how skilled a player is by using a grading system (as of right now it just the average of the ...
-2
votes
0answers
33 views

I’m a beginner building a terminal hangman app in which you can decide what the guessword for you opponent is [closed]

The following program directs you to a menu once you start it where you can either enter a new guessword or start the hangman game. By looking at it I think the code should work but once I press 2 to ...
2
votes
0answers
51 views

Using >= even though it's impossible for > to be true [closed]

I can't find an answer to this question either because it doesn't exist or because I am incapable of searching for it correctly. Consider this code which prints out the numbers from 1 to 12 ad ...
3
votes
2answers
33 views

Merge Sort Implementation and Optimization

This is Merge Sort that i implemented, i feel i can make it better esp the combination function. So i split the code into functions because i don't like seeing a bunch of spaghetti code in a single ...
4
votes
0answers
28 views

Text only turn based battle simulator

This is my first proper-ish project I've made. This was my first time using classes as well. I know that I made really stupid decisions, this is extremely far from being anywhere close to optimal, and ...
2
votes
1answer
38 views

Fast API path parameters from Enum Class

from enum import Enum from fastapi import FastAPI app = FastAPI() Hi Defined a route and a Enum Class for the same but the Enum Class looks ugly. ...
5
votes
1answer
34 views

Extract the data from Dicom files in an time efficient way

I am trying to extract and save images from a Dicom dataset. It is taking approximate 4-5 hours to process 1000 files. (Also, I am reading and saving files in an external hard drive so there is a time ...
6
votes
1answer
195 views

Handling errors in potentially incomplete responses

I am using the library geoip2 to get Geolocation of many IP adderesses ...
-5
votes
0answers
23 views

Generating a recursive list [closed]

Given a list of numbers p[i] for i=0,...,n what is the best way to generate a list N[i] in python where each element of N[i] is such that ...
-4
votes
0answers
24 views

Dict vs. tuple of tuples vs. ordered tuple [closed]

A function in a package I'm developing should take a list of IDs as input, make async calls to a server for each of the provided IDs and return server responses for each ID. I'm trying to choose ...
7
votes
1answer
151 views
+50

Faster and cleaner SHA-1 leading zero histogram with Python

I've written a python code for finding the distribution of the leading zeros of SHA-1. Using random inputs and hashing than counting. Normally it is expected to fit the ...
11
votes
1answer
117 views

Dungeon Ball, a Pygame

I just completed the first release for my first game on Python, called Dungeon Ball. I'm looking for people to test out the app and give me some feedback and constructive criticism. I'd like to use ...

1
2 3 4 5
252