Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

Filter by
Sorted by
Tagged with
7
votes
1answer
210 views

XOR Encryption, Decryption, and Cracking in Python

I have recently been working through a number of the Cryptopals Cryptography Challenges to try and improve my knowledge and understanding of both cryptography and Python. As five of the first six ...
3
votes
0answers
59 views

Split money into every possible combination of coin denominations

Background and objective of the code Based on this Dev.to challenge, I wrote the Python code below (TIO link also available). The task was to return the least number of coins in a given denomination ...
5
votes
2answers
410 views

Optimizing string analysis using slicing

I am currently taking back Python after over 6 years I do not use it, and to do that I am solving some small challenges on Hacker Rank. I wrote a code that works, but which is not performant and I ...
3
votes
2answers
53 views

Checking unique words and their abbreviations

In an attempt to solve a problem on Leetcode, I used dictionary and sets to have O(1) time complexity. However, my speed is too slow, better than just the 5% of Python submissions. Here is my code: <...
8
votes
1answer
153 views

Temperature unit converter in Python

I am starting to learn python and this has been my first project but I am not entirely happy, I think it could be done better. Could you help me? The strings are in Spanish but I think it does not ...
3
votes
2answers
65 views
2
votes
1answer
33 views

Scoring for loans

I created a python class called Score, I intend to use it to assign scores depending on 2 parameters, first the type of score - score name and second the user_input, so for example if I want to get ...
2
votes
2answers
81 views

Multiplying numpy arrays

I have written a function to multiply two numpy arrays. ...
3
votes
1answer
43 views

Extracting average time series

I have this JSON code that I got from a get request with Azure API. Everything works how I want it but it doesn't look good. There must be an easier way to parse the data. ...
1
vote
1answer
90 views

Getting the square of the difference between many points in a NumPy array

I have an array with 40000 numbers that are floats or ints. I need to perform some calculation. To do this I have used nested for loop, but the code is really slow. Can I use something instead of ...
5
votes
1answer
66 views

A Python Snake Game Using Pygame

My attempt at creating a snake game, in pygame. I tried to make it as simple as possible, but i feel it could be better in terms of best practice, and efficiency, along the idea of avoiding redundant ...
2
votes
1answer
78 views

Password generator project in Python

A few days ago I posted my password generator project to help me learn and become more comfortable. I got a lot of great replies from that and I've sense updated and would love another look at the ...
4
votes
1answer
60 views

Leetcode 957. Prison Cells After N Days

I am working on 957. Prison Cells After N Days but getting timeout error for my code. as I assume my code should be 14+O(n-14) about O(n) am I right since after 14 run pattern will be repeated? and ...
2
votes
1answer
74 views

Do I need to use inheritance and classes for my OOP webscraper? [closed]

I am currently writing python code that scrapes information from the web. I have to scrape several sites, but there a two types of procedures: Directly scrape from the website Download pdf and scrape ...
8
votes
1answer
53 views

Red-Black Tree Implementation in Python

i'm wondering if there are better practices, and optimizations, i could make on my code, to do things easier/faster. I have added comments, in many places in the code, to make understanding easier. <...
4
votes
3answers
87 views

Password Generator Python

I decided to make a password generator to get more familiar with Python. I had to break up the code into two boxes due to weird Stack Exchange highlighting with the triple quotes. How would you ...
8
votes
2answers
308 views

My Graph Implementation In Python

I have implemented a graph based on theory, and I'd like some advice regarding best practice, and thoughts about what i didn't implement that would make it even more useful, along with ideas that are ...
8
votes
2answers
665 views

Optimize function that returns length of a subarray

I did an exercise today on where the task is to write a function that returns the length of the longest subarray where the difference between the smallest and biggest value in the subarray is no more ...
5
votes
1answer
40 views

Using Newton Method in a Neural Network/

I programmed a Neural Network to do binary classification in python, and during the backpropagation step I used Newton-Raphson's method for optimization. Any kind of feedback would be appreciated, but ...
1
vote
1answer
32 views

Check that elements in list follow a specified date-format schema and are not null/na/nan [closed]

I'm practicing some data-analysis and I'm currently checking the integrity of my data. The elements that do not follow my date-schema, should be funneled to a new separate list so I can work on ...
7
votes
0answers
86 views

Calculating a unique count within a rolling time window

I have a Pandas DataFrame that contains a row per member per day, expressing member interaction with a website. Members interact only on some days, each member is identified with an ID. Here is a ...
3
votes
1answer
35 views

Web scraper for driver's license test times

I have created a small selenium script that checks for available times to write a test for a drivers license. The program runs every minute and takes approx 50 seconds to run. I have noticed that it's ...
3
votes
1answer
42 views

Class or not in Page Scraper (Python BeautifulSoup)

I am trying to figure out whether the below is better than just having a raw script or just a script with functions. ...
3
votes
1answer
30 views

Curve-fitting the transfer-function of an impedance network with LMFIT

I am using LMFIT to fit the transfer function of a large impedance network to measured data, this involves some ~20 parameters and ~40 lines of (naively implemented) computations. there are a lot of ...
14
votes
2answers
563 views

Blackjack with card representation visuals

To try and practice OOP, I've heard making a blackjack game can be really helpful; which it has been. I don't know how 'advanced' an implementation this is; but it has all the standard features, like ...
2
votes
1answer
151 views

Smart Tic Tac Toe, a reinforcement learning approach

I'm currently familiarizing myself with reinforcement learning (RL). For convenience, instead of manually entering coordinates in the terminal, I created a very simple UI for testing trained agents ...
2
votes
1answer
88 views

Super greedy algorithm for Exact Three Cover

I had trouble solving instances of Exact Three Cover with 100 units in input C. All in a reasonable amount of time. Mainly because the problem is NP-complete. So I came up with an approximate solution ...
2
votes
0answers
38 views

Genetic sequence analyzer that reads FASTA and GenBank file formats and outputs all possible gene products

I have updated my my gene sequencing program from my previous post. That post explains what each functions accomplish. If you need clarifications feel free to ask. Any tips to make the code more ...
7
votes
4answers
346 views

Finding the first pair of prime numbers that have some specified difference

I tried printing the first pair of prime number in between a list of numbers with a particular difference. But my run time is still too high (for large range of numbers). I want to reduce the run time ...
5
votes
3answers
96 views

CAN Bus testing

I am creating a Python 3.8 script that executes a series of tests that reads and writes information to and from a CAN bus network. I'm using the python-can and the cantools packages. I've managed to ...
3
votes
0answers
44 views

Chain operations on raster data

I am developing a workflow to perform a variety of operations on raster dataset using rasterio. My previous workflow involved lots of I/O when performing such operations on raster files. I would like ...
6
votes
1answer
57 views

GenBank to FASTA format using regular expressions without Biopython

This is a Biopython alternative with pretty straightforward code. How can I make this more concise? ...
3
votes
1answer
74 views

Get future events from Pinnacle API

My program makes API requests to Pinnacle Sports to retrieve future events and saves them to the database. Questions: Do I manage the database resources correctly? It takes about 3 seconds to check ...
1
vote
1answer
52 views

How to avoid using exec() and eval() in Python

I wrote a script to execute a service on the Forestry TEP platform via its REST API. This service has certain input parameters, some of them are numerical values, other strings or files. The current ...
2
votes
0answers
53 views

Performance challenge: Box operations (HackerRank) (C, Python)

Recently I've been doing some challenges on HackerRank and came across this one. First, I tried with Python, and then C. Both of my codes failed due to timeout restrictions. It would be very helpful, ...
2
votes
1answer
30 views

Improving time complexity for Count the Islands DFS

For game AI development, I am currently using a slight modification on the DFS "count the islands" problem (specification below) as a solution to the ...
5
votes
3answers
256 views

Find all numbers that are factors of one array and factor into the second array, then print their count

I'm working on a solution to the Following problem on Hackerrank, and I seem to have found a function that works for the purpose. However, I feel as though this is a very overdesigned solution to a ...
2
votes
2answers
73 views

Exercism: determine if a word or phrase is an isogram

The task: Determine if a word or phrase is an isogram. An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed ...
4
votes
4answers
168 views

Short code in Python Rock Paper Scissors

I am studying and practicing Python; this is my Rock-Paper-Scissors game I've built from scratch. I saw this task is for beginners. When writing this in all the examples I saw dozens of lines of code ...
15
votes
4answers
970 views

A top-like live monitor for virsh/kvm/qemu VM's

I needed a tool to monitor VM's running on my server in relatively real-time (similar to top or the many variants out there). The main things I need to keep track ...
3
votes
0answers
33 views

Splitting an image in batches of tiles

I have a large image and I am extracting and processing tiles in batches of a given size. A tile is normally a 256x256 region and batches are normally a power of 2. In the below example the number of ...
1
vote
1answer
43 views

Link downloaded subtitle files and video files

This code unzips the downloaded subtitle files and maps them to their corresponding video file. Currently, after pairing video files with their corresponding subtitle files, it links them by renaming ...
2
votes
2answers
62 views

Finding pupils to tutor

I am a Math tutor and I found the site https://www.yksityisopetus.fi/ where one can search pupils. I made a Python parser to find pupils that want Math teaching with at least 25 €/hour. Are there any ...
7
votes
1answer
68 views

“Jedi's riddle” challenge

The challenge can be found here. In short we have a recursive function, and we need to find when \$z_i\$ is equal to one. $$ \begin{align} z_1 &= 1\\ z_i &= z_{i-1} * a\ \%\ n\\ \...
7
votes
1answer
322 views

Folder Syncer in Python

I have made a script that syncs one folder to another. So if, for example, you saved some changes in a file in directory A, then that file would have the same ...
7
votes
1answer
52 views

Python - A Numeric Matrix Calculator/Processor

it's the second object oriented program i've worked on, more details on https://hyperskill.org/projects/96?goal=391. I've added as much documentation as needed, as a first time, to explain each ...
5
votes
1answer
260 views

Server in Python

I'm looking for a code review and code improvement for my own small server. The server accepts the requests: User Join,User Leave,User Text Notify Group Join, Group Leave, Group Notify Request Time. ...
2
votes
1answer
74 views

LeetCode 146: LRU Cache II

I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Problem Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...

1
2
3 4 5
84