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
0 answers
10 views

Avoid if statements or condense it

Can any one please help me to condense this code?: ...
user avatar
  • 231
2 votes
0 answers
10 views

Decorator implementation around xarray.open_dataset

If you want to download some grib data for yourself the script below will pull data range of data on an hourly interval from the google api. Extract some hrrr grib2 data ...
user avatar
-2 votes
0 answers
10 views

Python while loop - How to print last value without tab [closed]

I am working to create a program that creates a hailstone sequence and I'm nearly there except my last value is printing with a tab after it. I can't figure out how to fix my code below to not have a ...
user avatar
3 votes
1 answer
104 views

Resize image, blur image and overlay image

This code has the function of removing worthless borders from the original image and then: Generate a 1080x1080 image (Instagram default) to be used as a blurred background. Generate an image with a ...
user avatar
3 votes
1 answer
79 views

Check how many days a country has been independent

I have been using a website called 'CSNewbies' to learn Python and one of the tasks was to create a way for a user to check how many days a country has been independent. The countries are limited to ...
user avatar
6 votes
1 answer
211 views

Check stock status at a retailer

I am learning Python and wrote this code to check (every 10 mins) whether a product is available at a retailer, since it usually runs out of stock pretty quickly. It's working as expected, but can ...
user avatar
  • 61
2 votes
1 answer
76 views

Small shopping cart application - Solid Principles and Clean Code

I've recently had a technical interview where I had to identify code smells and refactor an existing code by applying the SOLID principles and implementing unit tests. It is a small shopping cart ...
user avatar
-1 votes
0 answers
29 views

Domain modelling of data intensive applications (crawler) [closed]

I am refactoring various microservices into a single monolith, this application is first and foremost a crawler, but which then will process the crawled data in various ways and will extract features, ...
user avatar
-1 votes
0 answers
14 views

Beginner looking for Critiques! Formatting an Excel for Tableau using Openpyxl [closed]

I just finished writing a script in openpyxl to automatically format a dataset so it can be placed into Tableau. The script is running and working as intended but I know there are some things that can ...
user avatar
0 votes
0 answers
27 views

Deterministically hash dictionary

I need to compute a deterministic hash for a JSON-serializable dictionary. This answer almost does the job, but there are a few problems. If dict1 == dict2 then I ...
user avatar
-1 votes
1 answer
51 views

Forecast experimental results based on temperature [closed]

I would really welcome any hints on making this code more concise please. In this example we have some experiment results. For each planned experiment We have predicted results based on 4 temperatures ...
user avatar
  • 3
0 votes
0 answers
61 views

Best design for a generic reader

My goal is to propose a generic interface to read all kind of document, without bothering of file extension (reading word, pdf, etc ...). First Implementation: My first attempt was to implement: a ...
user avatar
  • 273
0 votes
1 answer
43 views

Optimization using a differential evolution technique, ideally with a million iterations

I'm working on an optimization code using differential evolution to solve. However, it is taking a long time to get the solution. See that I have a variable called number_of_iterations that must equal ...
user avatar
4 votes
2 answers
52 views

Python Tkinter UI Pattern Password Code

This post is less of a question and more of a hope for people to see my code which I know is far from great and give me some direction or simple tips on improving the quality of it. Normal Stud: ...
user avatar
  • 41
-3 votes
0 answers
28 views

Whats the best way to pass many cli arguments between multiple functions in python? [closed]

I write a lot of cli tools in python. Most of my tools have something like this to get arguments: ...
user avatar
1 vote
2 answers
66 views

Comma code project from "Automate the Boring Stuff with Python"

...
user avatar
2 votes
1 answer
53 views

Credit Card Validation Check (Using Luhn's Algorithm)

...
user avatar
  • 323
1 vote
3 answers
46 views

Removing medications older than 180 days ago from a list

I have the following code which removes a dict from a list of dicts in Python based on ...
user avatar
  • 360
1 vote
0 answers
55 views

Renaming keys in a Dict[str, Any]

Given a Dict[str, Any] and a mapping of "key paths" to new names, produce a new dict in the shape of the original that ...
user avatar
  • 111
1 vote
4 answers
84 views

Beginner Python program assignment: calculate the total number of bugs collected in a week using a while loop

Beginning of program assignment has a bug collector input the amount of bugs collected each day of the week then outputs the total number of bugs in a print statement. My professor has forbid us from ...
user avatar
  • 11
2 votes
0 answers
31 views

Python program for the Longest Substring Without Repeating Characters

I write my Python program below for this Leetcode problem: Given a string s, find the length of the longest substring without repeating characters. Example 1: ...
user avatar
-2 votes
0 answers
36 views

My code makes a tron-like game in turtle graphics but I'm missing a key collision [closed]

So I'm doing the last part of my tron game which is to code the collision that happens when the 2nd players' tron bike hits the line of the 1st players tron bike. From there, whoever ran into the line ...
user avatar
  • 1
1 vote
0 answers
30 views

Hashing service for files or directories on a generic filesystem [closed]

my program requires a hash to be generated for files and folders for data integrity between transfers and file system events (if hash is different, file is not ready). For data integrity, I wish to ...
user avatar
2 votes
1 answer
46 views

Clear output line in terminal after use for countdown (different length strings)

The method to overwrite the same line is well known and I use it for countdown, but what about when the next output string has a different size and will be generated by a single print? That's the ...
user avatar
14 votes
3 answers
3k views

My 1 Week Python Journey — A Quiz Game that I made in Python

I started my Python Journey almost a week ago from now. I had been following a Youtube tutorial earlier, but switched to Harvard's CS50P instead. I decided on making a little Quiz Game with my ...
user avatar
  • 323
2 votes
1 answer
42 views

Get some cryptocurrency rates from coingecko api

I'm currently learning some aspects of PEP8 and Python programming in general. Could you please code-review this little piece of code for me? I would be glad to hear any, even the smallest comments, ...
user avatar
  • 23
3 votes
1 answer
42 views

Crawler/scraper for soccer match results

I wrote this code some time ago as part of the web-scraping learning. Every now and then I find mistakes in it, as well as I have doubts. Feedback please, is this code compliant with the common best ...
user avatar
5 votes
3 answers
300 views

Translating dictionary keys in complex nested Python structures

This is an actual work problem we had to solve. Put simply: given a structure (e.g. nested dictionaries) and a mapping of old dictionary keys to new ones, produce a new structure that is anatomically ...
user avatar
  • 51
3 votes
1 answer
89 views

Longest Palindromic Substring | Python Code Giving TLE

Problem Statement Given a string s , return the longest palindromic substring in s. Constraints ...
user avatar
0 votes
1 answer
34 views

Approximation of the multiplicative matrix inverse (linalg.inv ())

I am trying to compute the multiplicative inverse of a large matrix (~ >40,000x40,000). This can be done with e.g. numpy.linalg.inv or ...
user avatar
  • 103
6 votes
4 answers
883 views

Guessing the Number Game

I started my python journey 4 days ago. I am following a Youtube tutorial currently to understand the basics of Python. So bear in mind that I am REALLY new to this. I wanted to test myself a little ...
user avatar
  • 323
3 votes
1 answer
48 views

Open a file, by looking in an ordered list of directories (search path)

I have a small Python application that needs to load a few different files (templates and config files). It should look in a number of destinations, in the following order, and load the file from the ...
user avatar
0 votes
2 answers
63 views

12 hour to 24 hour time conversion

doing hackerrank challenges and been learning python3 for a month now, made this code to convert and return 12 hour to 24 hour time format in one of the challenges ...
user avatar
1 vote
0 answers
40 views

Python fractal tree generators

I wrote the scripts several days ago, they do exactly what I intended, but the performance is not very good, I am still stuck on for loops and don't know how to vectorize things, I wrote both scripts ...
user avatar
4 votes
2 answers
257 views

Another number-guessing game

I am a newbie in Python and would very much need help in arranging and setting out function. I have programmed a number guessing game. The outlook of the program is very messy but I don't where to fix ...
user avatar
  • 41
2 votes
1 answer
74 views

my first Tic-Tac-Toe game

This is my first post here, as I just started learning a bit of code pretty recently through "Automate Boring Stuff". In one exercise, to learn about dictionaries, it was shown how to build ...
user avatar
1 vote
1 answer
44 views

Program for creating custom directory listings

The following code was written to create custom directory listings for the Abyss Web Server. It attempts to provide an improved example of the included documentation for doing so in Python. However, ...
user avatar
1 vote
1 answer
33 views

Monster Maker application in Tkinter

I have a program that works okay (not fully completed) however, I would like to simplify things and create some classes and different .py files for my tkinter app as I feel that would help organize ...
user avatar
2 votes
1 answer
42 views

Simple backup script with file removal after 7 days

Here is the script that I would like reviewed for the following: Best practices and design pattern usage Correctness in unanticipated cases Possible error checking Any streamline updates/ideas are ...
user avatar
2 votes
1 answer
48 views

Design Tic Tac Toe Interview Problem [Python 3]

Practicing objected oriented design. This time, it's designing the TicTacToe game. One difference between the real TicTacToe game is that I've made my TicTacToe game to have variable sized board. ...
user avatar
  • 155
6 votes
1 answer
406 views

Determine a diver's table and schedule based on depth and duration

I'm new to coding but I'm particularly new to python. I wrote a program that will determine a diver's table and schedule(because it relates to my job). It essentially assigns a value from multiple ...
user avatar
3 votes
1 answer
262 views

Design Shopping Cart System Interview Problem [Python 3]

Just practicing some objected oriented design questions. Please let me know what can be improved to be more OOD and extensible. Thank you. Functional Requirements Cart can hold multiple products A ...
user avatar
  • 155
0 votes
1 answer
41 views

Identify IRC users with largest vocabulary ignoring links and short words

I wrote this script to figure out which users have the largest vocabulary on my irc server. I would like to see if there's any way to clarify what I consider a very quick script. It outputs a CSV ...
user avatar
  • 875
8 votes
3 answers
2k views

Determine if Hill or Valley

This is my accepted submission for LeetCode. The problem is You are given a 0-indexed integer array nums. An index i is part of ...
user avatar
6 votes
1 answer
100 views

Implementation and Testing of Exponential Search for scenario where we search the same array/list many times

Exponential Search is an optimization over binary search. Conceptually, when searching for a number target in a list of numbers ...
user avatar
  • 328
1 vote
1 answer
57 views

Adding string to a text file without duplicates

I have a function below, store_in_matchid_file, and it adds certain strings to a .txt file as long as that string doesn't already exist in the file. However that ...
user avatar
  • 31
1 vote
1 answer
48 views

Generate new column based on two columns of dataframe

I need to generate column a_b based on column a and column b of ...
user avatar
  • 135
0 votes
3 answers
97 views

A more elegant way to uniformly sample from non-negative integers with a fixed sum

Given a positive integer n, I would like to randomly output n non negative integers that sum to ...
user avatar
  • 191
12 votes
6 answers
2k views

One of my first Python projects - an adventure game

This is a simple text-based adventure game I made. I'm a beginner and I want to know if the code is optimal or if it can be improved. The story is not very complex, but I made it more for practicing ...
user avatar
5 votes
1 answer
190 views

Calculate the number of people occupied at each time interval

The following scripts calculate a list with the number of people occupied at each time interval. The intervals are defined by the timestamps of two consecutive events that come from the sorted list <...
user avatar
  • 53

1
2 3 4 5
294