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

Generate a ColumnDataSource for a bokeh histogram hover displaying the names of the units in each bar

I came up with the following setup_cds function as a solution to my own SO question. My question is: how could I improve it (especially the joining of the names ...
1
vote
1answer
35 views

Recursing function to create dir in python

I am trying to write a small function to safely create dir until dir until full path of file exists. I'm trying to do it in a recursing function and would love to get some feedback. ...
0
votes
2answers
60 views

Read .csv files and convert the rows into dict for looping

This script tries to parse .csv files and returns an iterable object to fetch one row at a time to do some process. It works fine but I think it needs improvements ...
3
votes
1answer
35 views

Python implementation of Kahn's Algorithm

Please provide any suggestions on the below code for Kahn's algorithm. Can it be implemented in a better manner, or be improved: ...
2
votes
0answers
13 views

One Class SVM algorithm taking too long

The data bellow shows part of my dataset, that is used to detect anomalies ...
6
votes
2answers
97 views

Compressing large jpeg images

I'm working with thousands of large image files in a regularly updated library. The following script does the job (on average reduces my file size ~95%) but costs me around 25 seconds to compress one ...
1
vote
1answer
25 views

Customized method for dataframe in my analysis module

Please download the file and save in home directory and extract it: https://www.dropbox.com/s/swtw8bk35zr1i6d/analyse.7z?dl=0 I can get some warrants info. ...
4
votes
0answers
32 views

Automatically encrypting text editor

I have written an automatically encrypting text editor (github link). The reasons that I wrote this program instead of using vim + gpg are: It's more convenient than vim + gpg (user only needs to ...
2
votes
1answer
17 views

Join ArcGIS tables in Python of plant greenness in response to prior month's rainfall

I am using Python 3.8 with ArcGIS Pro 2.5. This code creates a joined table where I match values for plant greenness in the current month with rainfall X number of months into the past. Each loop ...
4
votes
0answers
54 views
+50

Check whether a permutation with one fixed point can be rotated into one with two fixed points

A friend gave me the following riddle: Given n people with n distinct names, you place n names tags on a round table with n seats. If the n people now sit at those seats randomly such that exactly ...
2
votes
0answers
19 views

Remote to remote copying of files

I've written a function to copy files remote-to-remote using SCP command, paramiko, pexpect, and paramiko-sftp. I want to make my code efficient; I'm new to Python and I don't know how. Here's my ...
4
votes
1answer
63 views

Code for wireless communication work

I need some pointers on how I can speed up my code, as of now it is incredible slow for larger inputs. The way the code works is that the file Loc_Circle_50U.txt contains the true locations of 50 ...
0
votes
0answers
12 views

Simple two-mode camera for graphics engine

I have a camera class that I use with my graphics engine prototype. For context, the graphics engine is written in OpenGL(4.1) using Qt-bindings (PySide2), since I also used Qt as my window and ...
2
votes
0answers
21 views

A self contained parser generator implementation

This is a recreational project, I was trying to make a parser generator with a grammar inspired from: https://docs.python.org/3/reference/grammar.html Unfortunately, understanding that specific ...
1
vote
0answers
9 views

Improving loop through xml files ad add to DF

With this code, i loop through similar xml files and add them to a DataFrame. How can i make this code better so it is more pythonic? ...
2
votes
1answer
16 views

Simple GUI unit converter with tkinter

I happened to delve into tkinter and created a couple of mini projects so I could get more familiar with it. I was wondering if there was any portion of my code or code structure that is sloppily ...
-3
votes
0answers
14 views

Input in python3 [closed]

Can a program in python, take input in the same line like in C, where we can can use scanf to take input differentiated by space? And, how. In C, ...
-4
votes
0answers
13 views

Python Caesar cipher encryption [closed]

I have the majority of the code done for the encryption of the input and shift. I'm at a complete loss when trying to implement the capital letters to re-wrap around after trying to go beyond Z. Here ...
0
votes
1answer
23 views

Python Alien Blitz Game

Please review my Python Alien Blitz Game code. There are several points I'm keen to hear about. I used globals. Was that an evil choice given the context? In the past when I've tried to refactor ...
3
votes
1answer
213 views

USACO Arithmetic Progressions

The problem I'm solving is: given a length of an arithmetic progression, and a limit to the terms (see below), find all progressions that work. All terms of the progressions must be of the ...
5
votes
1answer
109 views

Simulation of virus growth

The gist of my program is to simulate the growth of some virus. I used (attempted) OOP concepts to break down the problem into chunks and have the chunks talk to each other. Not sure if my ...
1
vote
3answers
38 views

Scraping the Bundesliga table and saving it to CSV

Wrote my first mini-script to get data from the german football league table and save the data to a csv file. Do you like the approach or could I be more efficient? Thanks in advance! ...
-5
votes
0answers
24 views

hello world!!!- ANY WAY TO OPTIMIZE GIVEN CODE [closed]

`print('hello world') print('hllo word') print('helo Wrld') print('hell orld') print('helloworld')` OPTIMIZE THE GIVEN PROGRAM
-3
votes
2answers
43 views

How Do I Use Subtraction on a List? - Python [closed]

When using lists to store information, how does one perform math on it? No in a (list * y) sort of way or a a = (list(3)+list(4)) sort of way. Instead, something like this: List = [1, 2, 3, 4, 5, 6, ...
5
votes
1answer
717 views

Word jumble game

I took my basic Word jumble game and added some additional features to learn new stuff. My plan was not to have any pre-defined words coded in my python script but rather different group of words in a ...
0
votes
1answer
13 views

animate button presses in a sequence (tkinter)

I am attempting to animate the series of button presses in the simon game I am creating with tkinter. The animate method is called for each button that needs to be pressed in the series. It currently ...
0
votes
0answers
13 views

Inserting data from client-side to MySQL via Flask-Sqlalchemy

I am creating a Bill of Materials (BOM) web app with flask as a backend. As a part of this app I am inserting data into BomStructure table from ...
1
vote
1answer
41 views

Python prime finder

I wanted to try and learn multi-threading, so I thought it would be good to make a small program normally first and make it multi-threaded, so I made this prime finder. ...
3
votes
3answers
152 views

Given an array, find all its elements that can become a leader

I was successful in solving a challenge in codility, but my solution failed performance tests. How can I improve my solution? Challenge: Integers K, M and a non-empty array A consisting of N ...
11
votes
6answers
2k views
+300

Pushing all non empty items to the end of a list

I have a list like this list_ = [" ", " ", "X", " ", " ", "Z", " ", "Y", " "] I am writing a function that will result in ...
1
vote
1answer
20 views

Finding matches in Excel files, adding to a Pandas Dataframe

I have a business requirement where I have to read excel files and match each cell with a given keyword list and find the matches and write it into a dataframe. I have written the code, but when the ...
0
votes
1answer
21 views

naive suffix tree construction in Python

I'm not certain if my implementation is correct, it appears to be, but looking for any feedback as far as readability and efficiency goes. Obviously using dictionaries isn't particularly efficient ...
8
votes
2answers
319 views

Navigate objects from a path provided as a string

Recently I wrote a validator for some objects. To increase usability the validator gives the user hints on how to fix some of the found issues. Since the application is around something programmatic, ...
1
vote
1answer
85 views

Printing the last two digits of an exponential calculation

I am trying to create a program where a user inputs two numbers - a base and an exponent, while exponent is a binary number. Then prints out the last two digits of the result. My code is working well, ...
2
votes
0answers
35 views

ML text generating code with Python and Tensorflow

I wanted a simple code review for improvement to increase the efficiency of my text generating model. This model is taken from the official TensorFlow site but is being trained on different datasets. ...
-2
votes
1answer
30 views

Python code refactor to use multiprocessing [closed]

I have written some Python code that opens files one by one, does some work, and writes data onto the filesystem. I figured, I want to make use of my cores.I've refactored the program into this. <...
1
vote
0answers
19 views

Python put from txt file into array(multiple line) [closed]

Im kind new to programming and I'm working with STL files (in ASCII format). Basically I need to create an array of several lines, and in each line of that array I need to insert 12 positions of a ...
53
votes
3answers
71k views

Redirecting subprocesses' output (stdout and stderr) to the logging module

I'm working on a Python script and I was searching for a method to redirect stdout and stderr of a subprocess to the logging ...
-2
votes
0answers
18 views

Multi Digit Subtraction Calculator - Python [closed]

I was trying to make a multidigit calculator. A simple program, but I started python about 2 weeks ago, so I'm not very advanced. Anyway, I was trying to add the subtraction function into my ...
5
votes
3answers
484 views

Improvement on data normalization

I have a part of code that is loading a dataset and normalizing property values to [0, 1]. My implementation is: ...
2
votes
0answers
28 views

simple neural network in python

I've spent the last few days learning the beginnings of how to implement a simple neural network. I've gone through chapters 1 and 2 of this book and have tried to write my own NN with referrals to ...
2
votes
1answer
54 views

Find the Percentage from HackerRank

I am learning python by solving python module from HackerRank. This problem is Find the Percentage. You have a record of N students. Each record contains the student's name, and their percent ...
4
votes
1answer
100 views

Can this sampling code be vectorized or optimized?

I have some code that is slow because it loops over every row in an input matrix Y. Obviously, this code does not scale with the number of rows. I don't think it's ...
-2
votes
0answers
49 views

Python Virus Spread Simulation with Markov Chain Random Walking [closed]

So in the light of the current situation and because of a home lockdown in my country I decided to try myself in a simple SIR Model Simulation in which I create a simple world with people who could be ...
1
vote
2answers
77 views

increase speed & lower memory consumption of text normalization function

I'm trying to preprocess a large text document. I've written a text normalization function which takes a disproprtionate amount of time and memory. How can I format the function to lower these two? ...
6
votes
2answers
61 views

Fast execution of function which resembles matrix multiplication

I am trying to make the following function as fast as possible on large matrices. The matrices can have dimensions in the range of 10K-100K. The matrix values are always between 0 and 1. The function ...
3
votes
3answers
6k views

Finding the longest palindromic substring

I have the following code that works correctly. I am wondering if there is a simpler way to go about implementing my solution and/or if there is anything that looks non-standard in my code. If anyone ...
7
votes
2answers
127 views

Performance - Read large amount of XMLs and load into single csv

I am dealing with a large amount of XML files which I obtained from here https://clinicaltrials.gov/ct2/resources/download#DownloadAllData. The download yields around 300.000 XML files of similar ...

1
2 3 4 5
238