Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 answer
53 views

Python script for zlib decompression

I'm looking for feedback/improvement on code that I wrote. It's a function that scans a file for zlib headers and returns the header, offset, and decompressed data. In main, below the function, I use ...
user avatar
0 votes
1 answer
46 views

tkinter user interface skeleton for airport analysis application

I'm trying to make the following code meaningful as much as possible, using inheritance. The purpose is for learning. The App class is the most super class. And the Tabs class has inherited it. Can I ...
user avatar
  • 103
4 votes
2 answers
75 views

Read a file format with mixed CSV and non-CSV content

I have a file format that I need to read which contains blocks of CSV data interspersed by non-CSV (or at least, inconsistent CSV) lines. Other than the very first line of the file (which has comma-...
user avatar
  • 263
1 vote
0 answers
35 views

2-player Tic Tac Toe in Python using tkinter

I am somewhat a beginner programmer, and this is my first project using tkinter. Any advice, tips or feedback to improve would be appreciated. ...
user avatar
3 votes
3 answers
364 views

Function to resize an image whilst maintaining aspect ratio

I have the following function: ...
user avatar
  • 225
1 vote
0 answers
39 views

PyQt6 program that lets you adjust the HSV values of an RGB color

I don't know how to actually describe what this script does concisely. I am writing GUI programs using PyQt6, and I want the most beautiful palette for my programs, so I browsed Wikipedia for a bunch ...
user avatar
0 votes
0 answers
67 views

Constructing a dependency list recursively

I am trying to find if there is better way to do this recursion. I went through some examples of memoization but found myself struggling to implement that with my code. example data: db_data and ...
user avatar
  • 1
2 votes
2 answers
272 views

Find max value that is multiple of 3 in an array [closed]

Recently, I got a code test from NAB. Please take a look at this one and give me your idea. Find the max value of an array of N integers. E.g. ...
user avatar
5 votes
2 answers
275 views

CSV file parser with some checks for header fields and duplicate rows

I have built a sample Parser class on top of the csv module for basic checks that we normally need as the first step of pre-processing. I would love a bit of feedback on the code and any areas that I ...
user avatar
  • 161
0 votes
0 answers
12 views

Closest pair of points algorithm [duplicate]

My program needs to find the closest pair of points within a list of points. I can't import any libraries apart from the ones I have. I use the well known Divide and Conquer method. ...
user avatar
  • 11
2 votes
2 answers
86 views

Console guessing game in Python

What would make it better? This is my first Python project. Do help in making it better, for me to learn something new. ...
user avatar
-1 votes
1 answer
50 views

How can i refactor python numpy code? [closed]

...
user avatar
  • 5
0 votes
0 answers
31 views

Web Scraping - Python & BeautifulSoup

I'm new to Python, and well, I had to develop web scraping code & generate data CSV file. Here is what I have written so far: ...
user avatar
6 votes
1 answer
123 views

Binary search algorithm (Python 3.9)

New to using this platform and would like to familiarise myself with it so would just like to ask if I am exhibiting good practice with my programming. Started the online CS50 course today and thought ...
user avatar
5 votes
2 answers
686 views

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
user avatar
  • 153
6 votes
3 answers
673 views

Python analog clock with turtle - runs slow

I made a python analog clock program with turtle. The problem is, it takes about 1.4 seconds to loop, so it only moves the second hand every 1.4 seconds. Its probably cuz my computer is slow... ...
user avatar
2 votes
2 answers
59 views

Basic command-line Python calculator

I made this basic Python calculator. It just does addition, subtraction, division, and multlipication. I feel like the code is a mess, but it does what I want it to, and I feel like it does it ...
user avatar
3 votes
2 answers
85 views

Encryption algorithm for chat app

I'm working on a CLI chat app using Python and I've coded this encryption algorithm. I used hybrid encryption. This uses an AES key as the shared key for encryption and decryption and RSA to encrypt ...
user avatar
  • 27
2 votes
1 answer
55 views

List all files and folders within a SharePoint document library

Background: I have made two classes. The first is SharePointHandler, and contains a few functions that I intend on using to automate some actions on SharePoint. A ...
user avatar
1 vote
0 answers
33 views

5-element clipboard for copy+paste

This is some code that I wrote for fun because in some of my classes I had to copy and paste between different Google docs I had. So, I decided to write a python script that would let me copy up to 5 ...
user avatar
5 votes
1 answer
295 views

Breaking Bad name generator

I've created a script to print all periodic table symbolic permutations of a string. As seen in the opening credits of each episode of Breaking Bad: © 2010-2022 AMC Networks Entertainment LLC. ...
user avatar
0 votes
0 answers
22 views

Creating an image from data, and slicing it into zxy tile service

I have some data that comes out of a grib file. The values in the grib file come out in shape of (721, 1440). Each value ...
user avatar
0 votes
0 answers
20 views

Range Sum of BST Leetcode - Python pass by reference?

https://leetcode.com/problems/range-sum-of-bst/ I'm trying to solve this question using Python and the solution is quite straightforward, start from the root and brach left, right based on the value ...
user avatar
1 vote
2 answers
80 views

Closest Pair of Points - Optimizing Code for big sets of points

I'm trying to create an algorithm that finds the closest pair of points (2D) within a set of points. I'm using a divide and conquer method which is explained here Closest Pair of Points Algorithm. ...
user avatar
  • 11
5 votes
1 answer
91 views

Why is this tensor contraction so slow and how can I make it faster?

I am trying to calculate a specific complicated tensor contraction (of complex valued tensors) which appears as part of some other calculation and is called multiple times in a row, about 100 times or ...
user avatar
2 votes
1 answer
86 views

Python script to convert scripts to png files

I have written a Python script that converts scripts to png files, entirely by myself without anybody's help. A picture is worth more than a thousand words so I will let the picture do the ...
user avatar
0 votes
1 answer
59 views

Stacking Z axis on multiple [1440x720] DataFrames (X, Y)

Each datum represents a point in a 1440x720 image of the globe, The values are 0-9. Each new layer is of a higher elevation. I need to structure a DataFrame in a ...
user avatar
4 votes
4 answers
295 views

Making a list of length X with each cell being a list of length Y

My teacher gave us an assignment to write a function that gets as arguments an x and a y. It returns a list which is of length <...
user avatar
0 votes
1 answer
41 views

Calculate session between in and out and total working hours of session

Is there any way to improve this code: punch:0 -> in punch:1 -> out ...
user avatar
2 votes
1 answer
77 views

Text RPG in Python

I'm a beginner in python and my code looks a little cluttered and a lot of lines are being duplicated, so I was wondering if I could get some suggestions on how to declutter and improve? ...
user avatar
  • 29
3 votes
2 answers
96 views

Given a list of digits, construct the largest number divisible by 3

What is the performance of this program? What should I do differently to optimize performance (O(n))? How would you grade it relative to what defines an optimal, elegantly-written program? Input: A ...
user avatar
5 votes
0 answers
81 views

Python 3 script to make photo collages

I have written a Python script that takes a list of filenames of pictures and generates a photo collage of them. This is my most complex project yet, and I have written it completely by myself (like I ...
user avatar
4 votes
1 answer
89 views

Parsing an IP routing report with half a million lines into a PANDAS dataframe

I have a file that has around 440K lines of data. I need to read these data and find the actual "table" in the text file. Part of the text file looks like this. ...
user avatar
1 vote
0 answers
47 views

Python Sorting Algorithm Visualizer with Pygame

So I've written a Sorting Algorithms Visualizer according to this tutorial, but made some changes and add some features of my own. The visualization is made with Pygame (Which I never used before). ...
user avatar
  • 181
0 votes
1 answer
63 views

Calculate working Hours in given shift time

This is simple program to calculate working hours in given shift.. It is also return user sessions and presence of user shift. while this works fine. I would like suggestion to improve it. ...
user avatar
3 votes
1 answer
80 views

Python 3 number convertor that converts floats between decimal and bases 2-36

This is a Python 3 script that converts any real number (ints and floats) from decimal notation to any positional number system ...
user avatar
1 vote
2 answers
78 views

Transforming a string by combining same duplicate characters

I'm solving a programming puzzle that requires to transform an input string by replacing pairs of duplicate consecutive characters with an "incremented" character, recursively, e.g. "...
user avatar
0 votes
1 answer
87 views

Finding missing numbers in ranges

I have a list of (potentially overlapping) ranges, e.g [(3, 9), (8, 10), (1, 18)]. I need to process them in order and for each range calculate how many numbers ...
user avatar
2 votes
1 answer
93 views

Fetch CSV file into PANDAS and send report of Spotify statistics

I'm relatively new and self taught in Python. I've written this code which gets a CSV file from a website, plays around with the data then creates an email with information gleaned. I know this is too ...
user avatar
  • 23
3 votes
1 answer
57 views

KivyPlayer - first Kivy app

So I have decided to learn Kivy Framework. Did two small apps containing mainly just labels (so that doesn't count) and decided I am going to do a simple music player. Nothing fancy just to learn ...
user avatar
  • 456
0 votes
1 answer
28 views

Create-flask-app with a single commend

Lately I was creating a loot of flask apps and I was getting a bit annoyed typing each time all the commands (make venv, flask env, pip installing, gitignore...) So I decided to make a package that I ...
user avatar
  • 101
1 vote
0 answers
28 views

Creating a reusable DictWriter context manager

I want to simplify the repetitive work of creating a DictWriter in a with context manager. So I created a ...
user avatar
4 votes
1 answer
46 views

Shorten a SVG file created with Inkscape

I often use Inkscape for generating SVG images. However, these images contain data which doesn't seem to affect the visual output, so I want to remove it. To do that, I wrote the following code: ...
user avatar
0 votes
1 answer
83 views

Class that handles 'user' info

So I started learning how to code about 6 days ago and suddenly realized that I've really only been referencing my book and myself without any outside input. I'm learning python and the most complex ...
user avatar
1 vote
1 answer
77 views

Python password generator with Tkinter

I program in Python as a hobby and this week I decided to write a program that generates 16 character long passwords. I wrote this program as a class, which i rarely do. Because of this I think I ...
user avatar
3 votes
0 answers
116 views

Return a 2D matrix from a C++ function in Python: ctypes versus pybind11

I found two ways in which I can use a custom C++ function (returning a 2D matrix) in Python. One approach that uses the Python module ctypes and another that uses the Python module pybind11. Approach ...
user avatar
3 votes
2 answers
97 views

Multiple condition checking on array-like container in Python

I'm writing a function that validates array-like container to have correct type, length or to be hashable. Some of conditions may not be used for validation. ...
user avatar
2 votes
1 answer
84 views

Replace nested for loops when assigning intial conditions in a 4-dimensional array

I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
user avatar
  • 69
1 vote
0 answers
14 views

Django data migration - worked, but far from performant

Background: I am learning web dev and decided on the Django framework as an excuse to learn Python at the same time. (Background is stats with lots of R and ...
user avatar
3 votes
0 answers
44 views

Scrape classifications from Wikipedia with bs4

I wrote my first bs4 script that scrapes animal classifications from Wikipedia. It works as long as the classifications are stored within these tags ...
user avatar
  • 131