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
1
vote
0answers
25 views

Efficiently update matrix calculations in Python

I'm trying to create functions in Python that would update calculations for a matrix only for new entries. These functions are created within a Design class, where users would submit a design into an ...
2
votes
1answer
27 views

Recursive os.scandir() for copying/moving files preserving subdirectories

This is modified from the general recursive solution here: https://stackoverflow.com/a/54544211/42346 to, more specifically, copy/move files with a given extension from one directory to another whilst ...
5
votes
3answers
438 views

Check if two lists are permutations of the one another ( Improvement)

Task: . Complete the following function that determines if two lists contain the same elements, but not necessarily in the same order. The function would return true if the first list contains 5, 1, 0,...
0
votes
2answers
50 views

HashMap Implementation (dictionary) in Python

I attempted making a hashmap in python, and it was harder, due to some limitations but this is my version of dictionaries in python. Are there any way to simplify or do the same thing in less code ...
3
votes
1answer
51 views

Filter out unwanted substrings while generating all possible relevant substrings

Write a Program that determines where to add periods to a decimal string so that the resulting string is a valid IP address. There may be more than one valid IP address corresponding to a string, ...
16
votes
11answers
2k views

Check if array has the same number of even and odd values in Python

Task: Complete the following function that determines if the number of even and odd values in an list of Integers is the same. ...
-1
votes
1answer
39 views

Best way of converting a dynamic number of list items into variables in Python [closed]

I have a simple scrapy spider that crawls a page and returns H1 on the pages. Since, each page is unique, one cannot know how many h1's will be on the page. Since the scrapy spider returns a list, I ...
1
vote
1answer
65 views

Import huge XML data set into MongoDB while parsing data

I am currently working with the Stack Exchange Data Dump - to be more precise - with the dumped Posts.xml data set from Stack Overflow. What am I trying to achieve?...
1
vote
0answers
16 views

One form for multiple models in Django

I must allow user to add city, state and country if it is not already present in the drop-down. Then I must create the respective model instances and then update the city in the userprofile. The below ...
-4
votes
1answer
57 views

Finding The Largest Digit in a Number using a Recursive Function in Python [closed]

I tried it using the code given below. ...
0
votes
1answer
19 views

QCombobox Case selection - Pyside2 Index via Sqlite

I have a very simple file where I have a Qcombobox Filter. When you select the filter, I run through a case on the index and output results. So, on selection I trigger: ...
3
votes
0answers
76 views

Check the organization and code style of a small Python project

Could you look at my code for the completed training project of the Python Hangman game and tell me where you can improve the code style? Code on GitHub ...
3
votes
2answers
79 views

Dice rolling simulator, any ideas on implementing any features?

This is one of my mini project of dice rolling and I want to improve it further with more advanced Python. Maybe you have any ideas to improve the code itself? This code will ask the minimum and ...
2
votes
1answer
71 views

Accessing time series development data from World Bank API

I wrote a script that connects to World Bank API, gathers some data (indicators) for a number of countries, creates pd.DataFrame, and saves the result as xlsx file. What I had in mind when I was ...
4
votes
2answers
186 views

hangman with ten chances

So this is the code I wrote for hangman in python. I want to know of can shorten this code more further and make it look more professional ...
2
votes
1answer
34 views

rock paper scissors game simplify in Python

I wrote rock paper scissors game using what I have learnt yet.It is while,for statements,list,tuple,dictionary and such simple things only.So I am interested how can I simplify this code using only ...
4
votes
1answer
66 views

Life and death model in python

The basic idea of the code is that agents come into the world, they age and then die. I want to keep track of who is dead and who is alive. Eventually, they will do more things but I think there ...
5
votes
2answers
245 views

How can I make this better? Python Web scraping

I am 12 days old into Python and web scraping and managed to write my first ever automation script. Please review my code and point out blunders If any. What do I want to achieve? I want to scrape ...
8
votes
1answer
182 views

Clone of mobile game Ballz

I have made a clone of the mobile game Ballz, and it works quite well. However, there are a few problems: Performance. When I have more than 50 balls in the game, the FPS dips from 60. I am unsure ...
3
votes
1answer
81 views

Python class inheritance - creating pythonic naming, logic and functions

Motivation I have been trying to work on my first bigger scale Python project, however I am struggling to create pythonic solutions. Instead some of the functions (and especially the naming) I've ...
6
votes
2answers
259 views

LazyEnum with validation

Motivation In the standard Python library enum, a subclass of Enum would create all its members upon class creation. This can ...
0
votes
1answer
56 views

Factoring the powers of 2 in Python

The powers of 2 are trivial to factor because all powers of 2 have one 1-bit and the rest 0-bits. Just iterate minus one 0-bit as follows: 10000,1000,100,10,1. And then convert the binary strings into ...
4
votes
0answers
150 views

Deep map, Python

Goal: apply fn to every element of an arbitrarily nested iterable (tuple, list, dict, np.ndarray), including to iterables. Ex: ...
2
votes
0answers
29 views

Handling failures in DB transactions

This code is meant to retry the db operation when a DB connection breaks: OperationalError. A transaction can fail for example when a db is being restarted and a commit fails. Or when a network error ...
0
votes
0answers
17 views

VGG-16 encoder - decoder implementation

I've just started with Python and Tensorflow and I wondering if you can check my VGG-16 encoder - decoder implementation. I'm using Python 3.7.7 and Tensorflow 2.1.0. ...
2
votes
0answers
16 views

Code and Inputs on to use AWS temporary Credentials

I am adding below code for review as i am bit new to boto3. This Script adds tags (key and value) to All Volumes of EC2 listed in Excel. Is there any more effective way i could have written this? Also ...
9
votes
3answers
1k views

Simple Sudoku Solver in Python

This is my naive approach on implementing a Sudoku solver, which is okay for simple Sudokus like this: ...
1
vote
0answers
29 views

A math parser written in Python and using infix to postfix conversion

Ive written this code over the course of the last days and it seems to work. However I'm not an experienced Coder so I don't know if my code is efficient enough. Any advice for improvements or nez ...
1
vote
2answers
62 views

Find 2 numbers that multiply to a number and add to another number

Here is my code, however, I am unsure whether it is the fastest way to achieve this objective. ...
2
votes
0answers
41 views

Solving Exact Cover by Three Products in Python

I'm a computer-science hobbyist and found an NP-complete problem that is similar to both subset-product and Exact Cover by 3-sets. Here is a Reduction of Exact-Cover into my problem. I am multiplying ...
2
votes
2answers
68 views

Basic binary search in python

I just started learning to code during quarantine and whilst learning python, I created this program for a binary search. This is really basic so I assume that there is a way easier method. If anyone ...
4
votes
2answers
83 views

Ising model simulation using metropolis algorithm

I am new to this community; I have tried my best to respect the policy of the community. I have written the Monte Carlo metropolis algorithm for the ising model. I want to optimize the code. I have ...
0
votes
1answer
69 views

Python private variables in a class [closed]

I was reading about private variables and functions in Python and I managed to get almost everything except one thing. Is it recommended to write underscore before variables defined inside a function?...
0
votes
1answer
36 views

A Credit Payment Calculator

So I've attempted this project from hyperskills where you're asked to make a calculator script that can calculate annuity and differentiated payments given that 3 of 4 values are known. I think i went ...
0
votes
1answer
27 views

Am I dynamic filtering correctly in Django?

I needed a way to get URL parameters and put them and their values into a query set's .filter() if they exist. After a day of piecing together information from the ...
0
votes
1answer
37 views

Algorithm Divisible Sum Pairs

I did the Divisible Sum Pairs problem on HackerRank input: n is length of array ar, k is an integer value. a pair is define only if ar[i]+ar[j] is dividable by k where i < j. Problem: find ...
1
vote
0answers
25 views

Python3 BFS Flood Fill with Deque and 2D Indexing

I'm currently in a programming competition where time is key, therefore I'm trying to optimize my solution as much as possible. I am trying to implement a BFS Flood Fill solution on a map size of ...
6
votes
0answers
61 views

Recursive and iterative implementation on Kosaraju algorithm

Kosaraju algorithm is mainly phrased as two recursive subroutines running postorder DFS twice to mark SCCs with linear time complexity O(V+E) below, For each vertex u of the graph, mark u as ...
2
votes
0answers
29 views

JSON Class Extension

Any improvements? ...
5
votes
2answers
65 views

Number Base Conversion Problem Generator

A program that generates questions to train your number base conversion skills. This program is made to ask questions about octet, binary and hexadecimal. No other bases. It first asks a series of ...
5
votes
3answers
677 views

Prime sieve generator

I wrote a simple prime sieve in Python. But it ended up looking... ugly. I included a few of the most basic optimizations. When posting this question SE suggested a bunch of questions on the same ...
7
votes
1answer
210 views

Decorator to cache a function result for some time

I recently played around with a script that got some data from the Google API. As I didn't want to spam requests at the service (and potentially get blocked), I made this decorator, which caches the ...
3
votes
1answer
57 views

Finding tags and changing id attributes

I have the following code which works fine but the execution time is more which I want to reduce. I guess this happens since each file is opened and then the operation is performed. Is there a way to ...
0
votes
3answers
97 views

Get methods in module, Python

Goal: extract methods/functions defined in module. This excludes: Imports Lambda methods Magic methods Builtin methods Class methods Classes Non-original definitions (i.e. function assignments, ...
1
vote
0answers
19 views

Lazy loading generator for training a Keras network

A common use for Keras LSTM layers is to generate text. There are many examples showing you how to do it. The usual method is to convert the text into a sequence of tokens and then slice up the ...
2
votes
1answer
23 views

Time Tracker Using JSON

This is a simple command line interface program that just keeps track of duration spent on multiple tasks. Any areas of improvments are welcomed to be pointed out. ...
1
vote
0answers
9 views

normalizing django models

i try to make an app for a mobile store ...
-1
votes
2answers
55 views

Multiple inheritance of class broken up into modules [closed]

I have a class Main that uses fn(cls, ...) methods from several modules; they're used exclusively by ...
2
votes
1answer
37 views

Retrieving unspecified function arguments from external context (scope)

The Problem I have a module with several sibling classes that share a method with a similar name. These methods receive the same basic arguments, however, for a number of the sibling classes the ...
3
votes
0answers
52 views

kenken solver, python

I have written a series of functions to solve kenkens. The general strategy is to eliminate possibilities until only one remains for each cell. This first function eliminates all possibilities that ...