Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

Filter by
Sorted by
Tagged with
1
vote
0answers
9 views

Faster way of Floyd-Warshall

I've implemented the modified Floyd-Warshall method to determine all shortest paths between a pair of vertices (i.e., if there are multiple shortest paths between a vertex pair, then all of them are ...
1
vote
0answers
11 views

Effective fetching data algorithm

I'm fetching some data by using bs4, and want to know why access speed gets slower as my program progresses. I'm using thread, and I know threading isn't so fast because of GIL. My problem is that ...
-3
votes
0answers
17 views

Calling function in class in hotel reservation system (python) [on hold]

I dont know how to use and call the def function under class. I am not sure how to use the input data for the class. There are two text files which will be used, about the rooms: room id and price of ...
0
votes
1answer
36 views

What should I change in my currency converter?

everyone! I wrote a simple currency converter in Python. I'll appreciate some tips about how I can improve my little script; what new features would be nice to add to my project? Right now, my ...
10
votes
1answer
69 views

Pure python range implementation

I implemented class Range as an equivalent to Python built-in range for practicing purposes. No features were added. Hope it ...
1
vote
0answers
32 views

Script to download Annual Reports (~70,000 in total) from a Website

It's only 38 lines of code and I haven't worked with web scraping that much before. How heavy would my code be on their server? It's for Deep Learning purposes and I haven't ran it yet but ...
1
vote
0answers
25 views

MATLAB / vs Python np.linalg.solve, heat diffusion, Why Python is slow?

I am solving a simple 1D steady heat question using spectral method. I am a long time MATLAB and Mathematica user and trying to learn Python. I compare only linear solving times and Python is way ...
4
votes
0answers
29 views

Finding all simple (without internal cycles) paths in a directed graph with total >1.0 weight

Assume directed graph with each edge being weighted by some positive float. Problem: find all simple paths (in other words, ...
2
votes
0answers
18 views

Django Dashboard View

What does my code do? I use Django and in the following snippet, I use a class together with a TemplateView to render an HTML page. I already tried to simplify it with methods, but my code still looks ...
3
votes
0answers
28 views

Python script for parsing links

I wrote a test that parses links from a web page, and in a loop, clicks on each of them, and then returns to the main page. But, each iteration is accompanied by parsing the entire web page again and ...
3
votes
0answers
40 views

Convert text file to html?

I have a script that converts a text file to html. The text file is an output of a program (needle). The function takes the text file as an input. I am aware the script is awful. I use this function ...
3
votes
1answer
18 views

Using a thread to update a table automatically in Django

For my portfolio app using Django I made a thread that pulls out the usd exchange rates for various currencies every 6 hours and updates the database. The program kicks in as soon as the module ...
0
votes
2answers
67 views

Python code to continue if a certain type is seen, otherwise try again to get valid input

I am very very new to programming, and this is my first day using Python. I want to check to see if an input is of type 'int' and to proceed with my program if the user has entered an 'int', ...
22
votes
5answers
2k views

Python web-scraper to download table of transistor counts from Wikipedia

I have been looking for answers for how to easily scrape data from Wikipedia into a CSV file with Beautiful Soup. This is the code so far. Is there an easier way to do it? ...
-6
votes
0answers
38 views
8
votes
1answer
37 views

Break text into letters (regular Unicode graphemes+language specific digraphs)

In English, "Sh" is two letters. In other languages it's considered a single letter. I'm trying to calculate the length of a string in a Unicode aware way, with this in mind. I'm imagining a function ...
10
votes
3answers
880 views

Karazuba Algorithm with arbitrary bases

I'm working on an implementation of the Karazuba Algorithm. I created a class BN which represents a number in an arbitrary base (and supports elementary operations)...
11
votes
3answers
484 views

Mutable named tuple with default value and conditional rounding support

I have following code to create a mutable namedtuple. based my understand I can use dataclass to do it. is there a better way to do it or clean up the code? ...
2
votes
1answer
49 views

A small protein database

I am making a small database and these are the following files. The scripts are working. How can I improve my scripts? Are there any places where a problem could occur? I have yet to write tests for ...
7
votes
4answers
291 views

Sort files in a given folders and provide as a list

I have two folders query and subject. The following function sorts alphabetically and provides the query and subject as a separate list. The file names are mixed of numbers and I found the sort ...
5
votes
2answers
52 views

Looking for performance improvement of my custom dataframe aggregation function (Python/Pandas)

I would like to aggregate rows of my dataframe together, following those rules: Rows are grouped by "Id", and sorted by anticipation One row can only be aggregated with rows next to it, with the ...
9
votes
2answers
93 views

Simple Python3 Checkers

I'm a beginning "pythonist" my current task is to write a checkers game and I need some suggestions here and there: are the code style and literacy answering the criteria of python? are the modules ...
3
votes
1answer
78 views

Simple calculator in Python

This is my first ever Python program. I thought I would make a calculator that performs 5 operations: add, subtract, divide, multiply, power. I am aware Python has its own power function, called "pow",...
2
votes
0answers
19 views

Structure and Code of Tornado WebAPP

I wrote a test application to familiarize myself with the Tornado Python framework. The application currently generates a cookie that you can view and delete. I ...
3
votes
1answer
40 views

Run an external program and extract a pattern match along with the result file

The script takes two input files of protein sequences and runs an external program (installed in linux/MacOS). The result provides a text output file example output.. Identity percentage is extracted ...
1
vote
2answers
47 views

Extract three letter pattern from a given list

The code takes a list of names and extracts the three letter pattern from the names. Then return the list of names as a value in the dictionary with key as a pattern. The list name has a fixed naming ...
1
vote
3answers
169 views

Primality test in Python

Here is a working Python implementation of primality test. Is there something that I could change in code to achieve a better running time? For more information about algorithm see this post. ...
13
votes
2answers
952 views

Mean π: Archimedes vs. Gauss - π computation through generalized means

I've written this simplified code to compute Pi for educational/demonstration purposes. These methods are based upon the generalized means: see a presentation on Pi and the AGM. Archimedes' method ...
-3
votes
0answers
36 views

Project Euler #84 Monopoly [closed]

https://projecteuler.net/problem=84 Below is my current progress on this problem. There are two problems with my code that I know of. The first is that the Go to Jail square should never be landed on ...
5
votes
1answer
66 views

Python/Flask Password Manager

As a project to better my skills in Python, I wrote a password manager. It's a website that has user login/logout functionality, the ability to add websites and passwords, and displays the websites/...
1
vote
0answers
20 views

TypeTrainer OOP Tkinter program [closed]

I've been developing my first real python gui-program for a while now. Having watched some tutorials to tkinter and OOP I've gotten quite far, but now I just can't get my code to do what I want it to. ...
9
votes
3answers
1k views

Insert str into larger str in the most pythonic way

I want to insert a small str into a larger one in the most pythonic way. Maybe I missed a useful str method or function ? The function that insert the small str into the larger one is ...
2
votes
1answer
36 views

Changes all floats in a pandas DataFrame to string

Below I created a function to format all the floats in a pandas DataFrame to a specific precision (6 d.p) and convert to string for output to a GUI (hence why I didn't just change the pandas display ...
-1
votes
0answers
25 views

Read XML file using and store in postgres sql [closed]

I am writing the code but it is not shifting data in to postgrey sql. Here is my code. I am new to python. looking for help from experts ...
0
votes
1answer
51 views

Personal quiz with input validation

The object of the code is to prompt the user with a quiz and collect the g's, y's, 0's, and 1's and if there is more than one then the user passes (else, they fail). I am a beginner and would like to ...
2
votes
1answer
39 views

Django turn ChoiceField into a submit button

I have made a ChoiceField into a select and submit button and wondered if this is the correct approach. forms.py ...
5
votes
1answer
30 views

CandidateArchive for model-assisted multi-fidelity global search algorithm

For my research I'm working on global search methods where a candidate solution can have it's fitness (=score) evaluated in multiple fidelities (=accuracy levels). The goal of the ...
3
votes
1answer
56 views

Python List of Dictionaries to XLS

How may I optimize the following function to write a xls file from a list of dictionaries using the openpyxl library in Python? The current logic behind feels very very wrong The dict list: ...
2
votes
1answer
61 views

LeetCode - Merging piles of stones

This is a LeetCode Problem You have a pile of stones presented as an array. On each turn you must merge k consecutive piles of stones, starting from any pile you wish. You must continue merging ...
-1
votes
1answer
31 views

Python ANN Implementation [closed]

I recently learned about backpropagation online and tried to implement it. I am not sure I have it correct yet. I am confused and would love a second pair of eyes on this code. Please help me ...
-2
votes
0answers
19 views

Python Taxi Program [closed]

Im writing a python taxi program. Im trying to input an order date and verify it and keep getting syntax errors with my input. I also havent a clue on how to store the order and assign it a driver ...
-4
votes
0answers
22 views

Early Python Coding Assignment [closed]

This is Jordan Greenhut's code Homework 1 Python basics and flow control Given August 26th – Due September 8th In this assignment you have to develop a security program. Inside a while loop you will ...
14
votes
1answer
582 views

Maze generator & animator in Python

This is a follow up to this code and I still did not get the feedback on the drawing functions Maze generator in Python- Gif animator-Custom colors/sizes The code generates custom color and size ...
9
votes
4answers
891 views

Change-due function

I wrote a function to calculate the change due from a transaction. It also prints the number of twenties, tens, fives, ones, and coins required to meet the amount. I am looking for suggestions for a ...
3
votes
3answers
101 views

(Project Euler #1) Find the sum of all the multiples of 3 or 5 below 1000

I have decent experience in programming before (mostly C++), but I am very, very, very new to Python, and I decided to try out Project Euler as an exercise. Here's the description of Problem 1: If ...
2
votes
2answers
105 views

Counting block combinations I: Project Euler 114

Problem statement (For more detailed description (including pictures), please, visit the link): A row measuring seven units in length has red blocks with a minimum length of three units placed on ...
7
votes
2answers
698 views

Python implementation of atoi

I made an implementation of atoi (ascii to integer) in Python a while ago for fun, and I'd like to know what I could do to improve it. ...
4
votes
1answer
55 views

Meta-circular interpreter for lambda calculus in Python

For learning purpose, I've written a simple lambda calculus interpreter (plus 'Add'). I would like it to be the cleanest and most idiomatic possible. Can we make it as neat as the Haskell version? <...
0
votes
0answers
41 views

making a tree from the list make it more efficient? [closed]

lst = [[5, 3], [11, 5], [13, 3], [3, 5], [6, 1], [1, 3], [8, 6], [7, 2], [2, 2]] I want to make this list to the tree structure ...
-5
votes
0answers
40 views

how can I stop invalid inputs when comparing to tuple python [closed]

when asking the user for input if they put anything other than the 3 tuples it flags an error. how can i handle it to repeat until its a valid input? ...