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
4 views

Bounded spigot algorithms for e and pi in Python

I've written bounded spigot algorithms(Spigot Algorithm) for e and pi. I would like to understand if there is anything I can do to make this more efficient. I've done things already like move the ...
0
votes
0answers
67 views

How would i make this code better? [closed]

I've been coding in python for a while now and I'm trying to get better at writing comprehensible code and code that let's say a business would like. how would I improve? ...
3
votes
1answer
47 views

increase efficiency of loops and element-wise operations in PyTorch implementation

For any input symmetric matrix with zero diagonals W, I have the following implementation in PyTorch. I was wondering if the ...
6
votes
2answers
98 views

Random changes in a list of binary numbers

I have a list of N integers, e.g. intList=[1,7,3,1,5] with N=5 and all integers have a ...
22
votes
2answers
4k views

Printing 1,000,000 numbers in 1 sec. in Python

Here's a fairly simple task from CSES Problem Set - Permutations 1070 that reads: A permutation of integers 1,2, …, n is called beautiful if there are no adjacent elements whose difference is 1. ...
-3
votes
0answers
35 views

Python Conway's Game of Life Implementation [closed]

I am making Conway's game of life in python, and I am a beginner. I decided to use 6 functions overall to implement it and here they are: Function 1: create a blank grid input: nothing return: a blank ...
10
votes
0answers
48 views

Suggestions on cleaning up Flask app

I've written a little bit of code to pull data out of my FitBit and store it in a GCP database for further analysis. The project is available here, but what I'd like to ask about specifically is the ...
5
votes
1answer
25 views

Geometry Approximation of an Integral

I am looking for help for two things: 1.how precise this approximation is (such as Big O or percent error) 2. How efficient the algorithm for time / space usage. I created an algorithm to estimate an ...
1
vote
0answers
18 views

Creating tkinter widgets that can dynamically change configs

I have built a small tkinter program that I want to have a few different themes it can change between. In order to dynamically change the colours/font for each widget I have subclassed tkinter, and I ...
2
votes
2answers
49 views

LeetCode 8: String to Integer (atoi)

I'm posting a solution for LeetCode's "String to Integer (atoi)". If you'd like to review, please do. Thank you! Problem Implement atoi which converts a string to an integer. The function ...
1
vote
1answer
80 views

Leetcode atoi (string to integer)

link here I'll include a solution in Python and C++ and you can review one. I'm mostly interested in reviewing the C++ code which is a thing I recently started learning; those who don't know C++ can ...
4
votes
2answers
76 views

Best way to find the largest sorted suffix in a list - USACO Sleepy Cow Sorting Python

Solving this problem. Right now, my solution entails finding the largest sorted sublist, starting from the beginning, all the way to the end. However, I feel like the way I wrote the ...
2
votes
0answers
22 views

Gradient descent algorithm for solving localization problem in 3-dimensional space

Task This code accomplishes the Time Difference of Arrival (TDoA) multilateration problem (see) using gradient descent (known otherwise as steepest descent). Goal I'm looking to: a) Improve speed: In ...
3
votes
0answers
70 views

Python most effective way to process list objects

I'm writing a class that works with a list of objects of a specific type (which is defined as class attribute). The class can either append objects via the append method or receive them as an ...
4
votes
2answers
273 views

List of binary numbers: How many positions have a one and zero

I have a list of integers, e.g. i=[1,7,3,1,5] which I first transform to a list of the respective binary representations of length ...

15 30 50 per page
1
2 3 4 5
865