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
5
votes
0answers
16 views

Speeding up Python program that converts DOCX to PDF in Windows

This is meant to be a performance-centric question as this type of conversion is obviously very common. I'm wondering about the possibilities for making this process faster. I have a program that ...
3
votes
1answer
27 views

Pushing local repository to remote repository using python Github

The code should do the following in order: It should download/clone the public Github repository locally. It should remove all the git history (and branches) Use the Github API to create a new Github ...
2
votes
1answer
41 views

Algorithm to find all legal moves in Reversi game

Reversi Game: The image from the Reversi game: I have my algorithm to find all legal moves in Reversi game. Here's the code with comments: ...
2
votes
1answer
42 views

Find if duplicate items exists in a list of dictionaries

I am writing a script to read rows (records) from an excel file with xlrd package and then create a dictionary for each row. In next step, I append each dictionary to a list. After I finished reading ...
-2
votes
1answer
26 views

Array-indexed sum

...
11
votes
3answers
2k views

Why is my Sieve of Eratosthenes using generators so slow

This is my prime sieve based on the Sieve of Eratosthenes. ...
-5
votes
0answers
22 views

Why does it keep putting the same number? I believe it is an issue with the for loop [closed]

Note: This is simply for test and I do not plan on using for malicious reasons, just educational purposes ...
3
votes
0answers
29 views

Python : adding a columns with count of missing values by row

I have a big python data-frame and I am trying to add a column to it with average number of missing values by row. I have inherited some code that is working but I'd like to reduce memory usage by ...
2
votes
0answers
17 views

Django Calendar Model

I am building a doctor appointment app with Django and Django Rest Framework. The app will have the functionality for secretaries to add appointments to a Doctor's calendar, and each Doctor may have ...
5
votes
2answers
219 views

Finding the number of moves a knight can perform while standing on a given square

This is a problem from CodeSignal which can be founded over here Here is an image on what we have to do: Code ...
4
votes
1answer
90 views

Fetching API with requests.Session

I wrote a script that parses API on schedule (Tuesday-Saturday), downloading everything for the previous day. ...
1
vote
1answer
53 views

Most efficient solution for USACO: Cow Gymnastics - Python

I was trying to figure out this problem, and I did. However, my code is so abhorrently ugly that I want to tear out my eyeballs when I look at it: ...
-4
votes
0answers
27 views

Randomly selected integers from predetermined lists add up to specific input value [duplicate]

Hello im trying to write a Python code that selects integers from arrays up to a certain value. I wrote this code however the code uses every list once (as is intended). But sometimes it is still ...
-3
votes
0answers
26 views

Randomly selected values from predetermined arrays must add up to specific input value [closed]

Im trying to write a Python code that adds up random integers from specific lists to a specific value. My code picks a random variable from list POP and in that variable it picks an integer. It can ...
1
vote
0answers
23 views

How to speed up this numba based decision tree?

In order to improve the performance of this code fragment, I have speeded up some code fragments by using the numba. However, a frustrating thing is that the performance of this decision tree is bad. ...
3
votes
1answer
64 views

Can this numpy code be vectorized?

I've written the following function to produce n realizations of a CIR process for a given set of parameters: ...
8
votes
2answers
149 views

Making an array of spiral numbers

Context I was solving a task on CodeSignal here You can view the task on the link I provided above. I have also put the task at the bottom of the post. Code ...
3
votes
0answers
23 views

Approximation search source reconstruction localization algorithm

Goal To determine the coordinates of some signal source in a 3D space, given the coordinates of four observers and the time at which each saw the signal, as well as the velocity of the signal. ...
3
votes
1answer
50 views

Function for accessing and searching dictionaries using /slashed/paths (like xpath)

So I have some data being returned to me in the form of a deeply nested Dict and I need to parse multiple values from it which may or may not be there. I saw this library (https://github.com/...
-3
votes
0answers
42 views

My code is passing only few test cases [Trie data structure] [closed]

I have tested my code against all possible test cases. Ex: word present, not present in dictionary; given word is prefix of existing words, upper case, lower case. They passed. But not sure what I ...
3
votes
2answers
40 views

Counting the number of k-mers like monomers, dimers to hexamers from the fasta file

Anyone here who uses Python for solving bioinformatics problems. This is the code I have written for counting the number of k-mers like monomers, dimers to hexamers from the fasta file. You just have ...
3
votes
2answers
72 views

Blackjack script in Python

Recently I had a python test and, unfortunately, I failed. I'm going to re-do my test and the teacher gave me the tip to work more efficiently and clean. To practice this I made a blackjack game about ...
7
votes
0answers
137 views
+100

Convert an English sentence to German using Bahdanau Attention

Context I am following this tutorial . My mission is to convert an English sentence to a German sentence using Bahdanau Attention. Summary of the Code I first took the whole English and German ...
9
votes
3answers
106 views

CSES standard solution for range query problem giving TLE

Problem statement is from CSES This is a standard question where we are given a list of numbers and a number of queries. For each query, you have to give the sum of numbers in the given range. My ...
4
votes
1answer
63 views
-1
votes
0answers
59 views

Can somebody make this python game code smaller? [closed]

I was wondering if somebody can make this smaller for me. I wrote this in python. I need to fix some errors in the code and I need to shrink it. It's a game to guess the hidden shape. It's about 500 ...
3
votes
2answers
79 views

3-SAT Solver Python

I've written a 3-SAT solver based on this prompt: Alice recently started to work for a hardware design company and as a part of her job, she needs to identify defects in fabricated integrated ...
2
votes
0answers
26 views

Converts Pandas and Numpy into Dictionary and Converts back to original format for data split

I'm trying to refactor some code so that this it does not have so much repetition to it. What I'm trying to do is create an input for a multiple channel/input neural network. The features that are ...
0
votes
0answers
26 views

Face detection and smoothing [closed]

I am working on rewriting a lot of code I have done of the past couple years to better myself with the things I have learned. I am not sure if this is the right place but I would love review of my ...
12
votes
5answers
781 views

Array manipulation: add a value to each of the array elements between two given indices

This is a Hackerrank problem: https://www.hackerrank.com/challenges/crush/problem You are given a list of size \$N\$, initialized with zeroes. You have to perform \$M\$ operations on the list and ...
8
votes
2answers
56 views

The console prints a list of items for the user to scroll through using the up and down arrow keys

I am somewhat new to python (yes I know, a cliché statement) and I wrote this code to scroll through a tuple of strings using the arrow keys. I know that the code is sloppy but I don't know how. Any ...
-4
votes
0answers
43 views

List index out of range, but I tried to debug it and I can't find any errors [closed]

I am making a N-queens algorithm (The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other; thus, a solution requires that no ...
10
votes
2answers
707 views

Basic python calculator

I have a young friend of mine who is starting to learn Python in school and asked me to give him a little assignment. I am in no way a teacher nor a Python expert, but I accepted. At first I thought ...
0
votes
0answers
33 views

Using inspect.signature with higher order functions in Python: good practice? [closed]

Consider a function that accepts a Callable as a parameter and a dictionary of arguments as another then simply applies the parameters to the function: ...
5
votes
2answers
51 views

NEA Computing Task 2 Dice Game

I was recently set Task 2 as seen below and I realise someone answer the question on this site here but I wanted a fresh opinion TASK 2: Allows two players to enter their details, which are then ...
-1
votes
0answers
17 views

Is there a way to find Shapiro-Wilk p-values [closed]

I have tried to find p values for my test statistic, but I got following error value: The codes for test statistic and data 7 in here ''' compute Shapiro-Wilk p-values ...
1
vote
0answers
84 views

Generate many, many folders fast

I've made a program which makes the folders a-z, and in each of those makes the folders a-z, and in each of... you get it. many, many folders. its quite slow at the moment, would there be any way to ...
6
votes
2answers
210 views

Solution discussion on the best way to reverse a number in Python

I'm practicing some python exercise and I have some doubts about the solution of reversing a number. Example, 42 -> 24, -314 -> -413. The book has this solution: ...
9
votes
5answers
2k views

Efficiently find all the Pythagorean triplets where all numbers less than 1000

How can I make this code run faster: ...
7
votes
2answers
513 views

Number of occurrences of strings in array

This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem). We're given an array of strings and an array of queries, and have to return an array of the number of ...
14
votes
3answers
2k views

Python3 - merge sort, O(n) space efficiency

Any critique of my implementation of Merge sort would be much appreciated! I tested it using a driver function (shown below), and everything works. However, it still feels unwieldy, I am a beginner ...
6
votes
1answer
81 views

Sinewaves and FFT plotter

I am trying to code a sin wave with 5 sliders: frequency, amplitude, phase change, number of data points, and time. I am currently trying to link my phase change slider with my graph so that it ...
3
votes
0answers
50 views

Getting the minimum possible value from list consist of '0' and '1' by multiply no. of [0,1] and add the result after sliced in 'k' section [closed]

This code write to determine a way to place the N horses into the K stables, so that the total coefficient of unhappiness is minimized. I use python to write a code and I want to reduce the running ...
15
votes
1answer
1k views

Downloader in Python

I wrote this code in python and it works fine for me but I do know that the code is not optimised and a lot of refactoring needs to be done. So I need review on how this code can be improved. I ...
2
votes
1answer
58 views

program that fully documents every file on drive

I have a program which goes through your drive and does two things: For every file extension it creates a file "file of extension_name" and whenever it encounters a file with that extension,...
5
votes
2answers
152 views

Find words in a word grid

I made a program to find words in a word grid. It will find words that are horizontal, vertical, positive sloped and vertical sloped, all in both forwards and backwards. Here is my code: ...
5
votes
1answer
66 views

New Year Chaos (HackerRank problem) - find minimum swap count

The goal of the function is to find and print the minimum number of swaps (bribes) in what was initially a sorted array of ints - https://www.hackerrank.com/challenges/new-year-chaos/problem I have ...
8
votes
2answers
362 views

guess your number

Simple script that asks you to think of a number between 1 and 63 then offers list of numbers and asks if your number is in that list. Can this be refactored further? Are there better ways to create ...
5
votes
1answer
58 views

Python history quiz program

This program allows users to manage questions and quiz users from years of historical events. I'm looking for suggestions on how can I better organize my code, maybe apply OOP for functions and avoid ...
4
votes
2answers
77 views

Password strength checker (Udemy course)

This program is a project out of Udemy course. Kindly request you to review my code and suggest insights to better it. It takes your password hashes (sha1) and then sends hashedpassword[:5] to https://...

1
2 3 4 5
258