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
2 votes
1 answer
34 views

Python snippet for bulk moving files into their parent folder

I wrote this little snippet which moves files from several subfolders to their parent folder. Since the snippet uses different nested for loops I was wondering if it could be refactored to a cleaner ...
user avatar
  • 23
2 votes
2 answers
148 views

Transforming a list of dictionaries into a dictionary with nested dictionaries

My code takes a list of dictionaries as an input. Each of these dictionaries contains a person identified by name and a region code ...
user avatar
3 votes
1 answer
107 views

gradient descent implementation

I am attempting to implement my neural net for a fully connected network configuration. I don't know much about neural networks and ai, so the implementation is not great and may contain errors ...
user avatar
2 votes
0 answers
46 views

Implementing a data extraction pipeline with Bash

I wrote the following scripts to extract data from BigQuery and InfluxDB using the bigquery cli and the influx cli. The code works as expected. I included all files for completeness, but I'm primarily ...
user avatar
6 votes
1 answer
357 views

Create an image made of many circles

I have written some Python code for creating an image made of lots of circles. It works, but I wonder if it could be made faster, shorter or more pythonic somehow. Example image (took 28 seconds): <...
user avatar
4 votes
1 answer
97 views

Modeling global warming with a sinusoidal fit in Python

I would like to model global warming from temperature records recorded daily from June 1920 to October 2019 in Montélimar on Python. To do this, I would first like to model these seasonal variations ...
user avatar
  • 41
0 votes
1 answer
62 views

A text based DND game, (im 3 months into coding)

This is going to include my original code, and also revisions I have made, so far I have gotten some help on my character creations portion, and have revised it. I just would like input as to where I ...
user avatar
  • 9
1 vote
1 answer
37 views

Synchronization \ backup of directories and files (Python)

stackexchange members. I'm just learning to write. I set myself a task a few days ago and today I completed its implementation. The task was to create a "backupper" (I was inspired just by ...
user avatar
1 vote
1 answer
80 views

Parse a log file into separate column files

This is a follow-up to https://stackoverflow.com/questions/71194832/converting-json-based-log-into-column-format-i-e-one-file-per-column . My task is to optimize this code whose function is to convert ...
user avatar
11 votes
2 answers
598 views

Calculator using variable names

I've recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions....
user avatar
5 votes
2 answers
377 views

Sort a Python list of strings where each item is made with letters and numbers

I have a set of strings that all consist of one or two letters followed by one or two digits. I need to sort by the letters then by the numeric value of the digits. My solution is quite inefficient ...
user avatar
  • 789
6 votes
2 answers
122 views

An electron configuration writer given the number of electrons

I'm new to programming, especially Python (started in python3) and I want to ask if this piece of code is good enough or not. This is part of my personal project, that is, to make a personal library ...
user avatar
  • 163
3 votes
1 answer
68 views

Number partitioning: how to allow both 'light' and 'heavy' output?

I am working on a library for algorithms for multiway number partitioning. One challenge I face is that some users need the entire partition, while other users need only the sums of the parts. For ...
user avatar
6 votes
2 answers
919 views

Comparison function returning -1, 0 or +1

I was solving this: Write a compare function that returns 1 if x > y, 0 if x == y, and -1 if x < y. Writing the code, it seemed that after the first if ...
user avatar
2 votes
1 answer
73 views

Calculate reservoir volume after rain falls

I want to get better at commenting ...
user avatar
  • 31
7 votes
2 answers
526 views

Function that checks Fermat’s Theorem for a set of values

This is a challenge from Think Python 2nd Edition: Fermat’s Last Theorem says that there are no positive integers a, b, and c such that aⁿ + bⁿ = cⁿ. for any values of n greater than 2. Write a ...
user avatar
4 votes
0 answers
124 views

A skinny json-sql modeller targeting PostgreSQL

Over the last year, I have been slowly building an abstract class for deserialisation, and it has sort of morphed into a lightweight JSON-SQL modeler targeting PostgreSQL with ...
user avatar
  • 45
5 votes
1 answer
171 views

Given a number of points, generates all paths between all points that does not overlap

I wrote this code in 4 days, I want to see if I can optimize this code some more, and have some suggestion on what can I improve. This code takes in any number of points then naming them ...
user avatar
1 vote
0 answers
159 views

Python Wordle solver

I created a Python script that solves Wordle (more specifically this version: https://mywordle.org), it uses a wordlist of all possible answers, it is working perfectly and it rarely loses, you can ...
user avatar
6 votes
1 answer
381 views

LFU Cache implementation in Python 3

Need some feedback on this implementation of LFU cache in python3. Original problem : https://leetcode.com/problems/lfu-cache/ Would really appreciate some feedback on readability, understandability ...
user avatar
  • 63
3 votes
1 answer
118 views

Vincenty's distance Direct formulae numpy

I've refactored a function from the pygc library used to generate the great_circle. The Vincenty's equation below can be found ...
user avatar
1 vote
1 answer
68 views

Python module to generate context for Django template using data requested from API

As part of a university assignment, I have been tasked with populating and rendering a provided Django template with COVID-19-related quarantine data retrieved from a government API. To challenge ...
user avatar
  • 15
3 votes
1 answer
278 views

Python function to output a string that is justified to the right

I just solved this exercise from Think Python, 2nd edition: Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
user avatar
-1 votes
1 answer
56 views

Any better script using regular expressions? [closed]

...
user avatar
  • 3
8 votes
3 answers
797 views

Finding the perfect statline for a roleplaying game using Python

I made a program for fun that tries to roll a perfect statline, i.e a statline with two groups of only 18s, for a role-playing game. I'm still a newbie in python so mainly trying to learn how to make ...
user avatar
3 votes
2 answers
122 views

Python random number guessing game

I've been learning Python for about 4 days now. Python is my first programming language, so I'm not that good at coding yet. I have been programming a little random number game as my first project and ...
user avatar
0 votes
1 answer
74 views

Outputting a graphic using functions

How would you make this piece of code more simple/efficient? The problem should not be solved with one print statement, rather with functions Could you also give me any advice how I can come to your ...
user avatar
4 votes
2 answers
90 views

Binary Search Tree - My own version of delete function

Well, I am recently learning data structures and algorithms and I came across the Binary search tree and decided to first time use my own logic to make the delete function. I have not come across a ...
user avatar
-1 votes
1 answer
89 views

Vending Machine give changes after they select the menu [closed]

The program offers items, has the user pay for items, 'gives' the items. It seems to work more or less. I have 2 questions: I don't know how to deduct the cash from cash it is deposited and when they ...
user avatar
0 votes
1 answer
81 views

basic tic tac toe

I looked a little into HTML a year ago but decided to try python yesterday and came up with this for tic-tac-toe. I have no programming experience and I haven't yet looked at other peoples versions of ...
user avatar
  • 11
0 votes
1 answer
71 views

Apply a funtion to each element of a dataframe according to other elements values in the corresponding row in pandas and python

I am a little new in the Pandas and Python framework. I would like to understand if my code is more or less fine or it too related to my old program framework way of thinking. I have this is the input ...
user avatar
  • 101
6 votes
1 answer
357 views

Count lengths of constant subarrays

I have an array assuming discrete values. For each value, I am interested in how often it is assumed in a row. For instance, if my array is ...
user avatar
0 votes
0 answers
51 views

Creating attendance records from unstructured attendance machine punch timestamps

I'm trying to create attendance records (that have entry log on and exit log out) from machine attendance logs, the machine logs records have: a user id, and a timestamp (which is a datetime variable)....
user avatar
2 votes
1 answer
97 views

Finding the next palindrome number

I wrote a piece of code that generates the next palindromic number and that works fine. However I feel like my code isn't as efficient as it could be. Are there any tweaks that I could implement to ...
user avatar
3 votes
1 answer
68 views

PixelArt made with pygame

I am a bit new to pygame, and I made this simple pixel art game. Is it possible to simplify, and is it possible to save your drawings and load them back again? ...
user avatar
9 votes
1 answer
876 views

Python script to analyse Apache log files

I am fairly new to Python programming language. Most of python programmers have heard the philosophy behind the python programming language. The code should be easy to read, easy to understand, simple,...
user avatar
0 votes
0 answers
22 views

Testsuite for implementation of the command pattern

I've attempted to introduce the command pattern for my use-cases. I would like some feedback on my Test suite. I've tried to delegate as much responsibility to other classes/functions so the primary ...
user avatar
  • 153
5 votes
2 answers
556 views

Guessing game - Too high. Too low

I will post 2 scripts that are doing (supposedly) the same thing. First one is the script i created, second one is the solution from the course. What would you consider wrong (if anything) with the ...
user avatar
  • 59
3 votes
1 answer
36 views

Exporting a merged dataset from multiple source to a downloadable link

I'm working on a use case in hobby project where I am merging data from an external data source with an internal one and exporting that to a downloadable file The use case is exposed in an ...
user avatar
  • 153
2 votes
0 answers
34 views

CodeReview: CycleGAN Implementation Using Keras FunctionalAPI

Okay So I Am Here Implementing the cyclegan architecture with using keras api from scratch. For Those who Wanna Know More About Cyclegan seehere The CycleGan Compose of Two Phase Architecture Like ...
user avatar
6 votes
0 answers
106 views

Python asyncio multithread wrapper

For my application, I needed a lightweight way to launch multiple tasks and monitor their completion in a main loop periodically or use callbacks. The main loop is going to be busy most of the time ...
user avatar
3 votes
1 answer
75 views

Blackjack game in python w/ bot

I am a beginner programmer and this is my first project, a blackjack game with a functioning dealer in python. Any feedback would be appreciated (especially if its about bot improvement). ...
user avatar
2 votes
1 answer
207 views

Tic Tac Toe game v2

I made the changes that were suggested to improve the program in the previous version. I would like to know if there is anything to improve in terms of handling object oriented programming, variable/...
user avatar
2 votes
1 answer
68 views

Encode non-negative integer to a string of ascii letters and digits

I want to encode a non-negative integer to ASCII letters and digits. I wrote below code for that, that works, but which I assume too immature to use in production. ...
user avatar
0 votes
1 answer
72 views

Calculating the value of a stock-portfolio over time using Python Pandas

I am quite at the beginning of learning Python and decided to start my own little coding project to improve my skills. The goal of my project is to simulate the past growth of a stock portfolio based ...
user avatar
0 votes
0 answers
28 views

MNIST classifier and autoencoder: 2 in 1 deal

I built an autoencoder with a latent space of dimension 10 that doubles as a classifier (the predicted digit is the argmax of the latent space). This was obtained by optimizing both the digit ...
user avatar
  • 27k
3 votes
1 answer
129 views

Numerical integration in Python involving four dimensions

I'm trying to obtain the following S2 from a given S1, $$ S2(i, j) = \sum _{k=0} ^i \sum _{l=0} ^j S1(k, i-k, j, l) e^{ -\sqrt{...
user avatar
4 votes
1 answer
66 views

3D to 4D surface fitter converter

I recently wrote this bit of code while trying to convert a 3D surface fitter to a 4D one. The solution works and I didn't want to leave the next guy to grind out the solution so I made the code as ...
user avatar
0 votes
1 answer
74 views

User, Company, Company User and Post relationship

The use case of an application is there will be two kinds of user. One normal user and another company user. The requirement is Normal user can follow company and see their posts A company has ...
user avatar
  • 211
3 votes
0 answers
79 views

Build the Mountain Car Environment using coupled inheritance and type annotations

This code builds the environment for the standard Mountain Car Problem of reinforcement learning. I'm using Python 3.9 with PyCharm and I'm wishing to use type annotations throughout. I'm trying to ...
user avatar

1
3 4
5
6 7
292