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
2
votes
2answers
379 views

Regex version of strip() - Ch. 7 Automate the Boring Stuff

Here is a practice exercise — Regex version of strip() \$-\$ Write a function that takes a string and does the same thing as the ...
5
votes
2answers
380 views

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

Here is a practice exercise — Fantasy Game Inventory \$-\$ You are creating a fantasy video game. The data structure to model the player’s inventory will be a dictionary where the keys are string ...
0
votes
2answers
71 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
5
votes
2answers
98 views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...
6
votes
2answers
107 views

Class to generate a pdf invoice

I am learning to work with OOP design patterns and so I challenged myself with the idea of creating a way to generate a pdf invoice based on some information entered. So, this is what I have done so ...
5
votes
0answers
63 views

Parsing Long Excel Report Files for Predefined Results

I work as an IT intern in a multinational and I was given a tedious task of combing through a 2500+ long multi-column excel report file in search of inactive servers. Here's a sample row from that ...
6
votes
1answer
48 views

Updating generated file

With this algorithm I update an automatically generated verilog-file. The update within this file is done by commenting the assigned wires to specific ports of module instances. Is there a better, ...
1
vote
2answers
46 views

Leetcode 15 - 3 sum

This is a Leetcode problem - Given an array nums of n integers, are there elements \$a, b, c\$ in ...
7
votes
2answers
481 views

Word-Ladder solver in Python 3

Follow-up to Python program to find a word ladder transforming "four" to "five" I'm trying to write a program to solve a word ladder puzzle to brush up on my Python. For those who ...
3
votes
0answers
35 views

(Leetcode) Snakes and Ladders

This is a Leetcode problem - On an \$N\$ x \$N\$ board, the numbers from 1 to N * N are ...
5
votes
1answer
88 views

Shortest pathway across a snakes and ladders board (Update)

Earlier I posted a fairly inefficient recursive solution to the problem of getting across a snakes and ladders board in the smallest number of moves. I have created a much faster solution to this ...
14
votes
4answers
3k views

100-doors puzzle

Here is a very simple solution to the 100 doors challenge You are in a hotel with 100 doors. Initially every door is closed. On the first round, you change the state of every door (if it is open, ...
7
votes
1answer
1k views

Python program to find a word ladder transforming “four” to “five”

I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform "four" to "five", forming a new four-letter word at each step, replacing one letter ...
4
votes
4answers
185 views

Find the nth term of a sequence that consists of Fibonacci and prime numbers interleaved

I have given a series problem 1,2,1,3,2,5,3,7,5.... in which the odd terms forms the Fibonacci series and even terms form the prime number series. I have to write a code in which I have to find the ...
2
votes
1answer
49 views

Select optimal piecewise regression fit

I'm making a program which fits a piecewise linear regression with up to 4-5 breakpoints in the data, and then deciding how many breakpoints is best to prevent over and underfitting. However, my code ...
4
votes
1answer
59 views

Pick the best combination of n choose k models

Algorithm Let \$M_0\$ denote the null model which contains no predictors. This model simply predicts the sample mean of each observation. For \$k=1,2,\ldots,n\$: Fit all \$n \choose k\...
3
votes
2answers
68 views

Optimizing Luhn check digit algorithm

The internet as a whole and Code Review in special already provide a decent amount of implementations of the Luhn check digit algorithm. They often follow a relatively "naive" strategy, in that they ...
6
votes
1answer
49 views

Irreversibly hash email addresses while preserving format/entropy

I'm looking to irreversibly hash valid email addresses which have been parsed from mail log data as part of a machine learning project. I need to ensure that the processed data has been scrubbed of ...
11
votes
1answer
182 views

Simple log rotation script

I created a simple script that implements log rotation. It checks the log file size (say, out.log) if it exceeds 5MB limit. If it does then the script copies it to <...
0
votes
2answers
130 views

(Leetcode) Brick wall

I would like to know whether I could make my solution to this Leetcode challenge much faster. There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The ...
1
vote
0answers
34 views

Project Management System focused on forking and web-of-trusting-code

I'm writing a project management system focused on forking and web-of-trusting-code, which is a fancy way of saying "take someone's code, do whatever you want with it, and see if others agree with you"...
1
vote
1answer
54 views

Python xml-parsing script

I have a Python code that deals with parsing xml-feeds of footwear online stores. I want to let the code look more professional for the sake of optimal reusability for other programmers. It includes ...
4
votes
2answers
57 views

Python logging-module that writes to both the console and a file

I've created a small module with a function plog() that allows to easily print to both a log file and the console. It also creates a directory "log" at the location ...
4
votes
2answers
87 views

Find the in-order successor of a given node in a binary search tree

I have an implementation of an algorithm to return the in-order successor of a given node in a binary search tree. We are allowed to assume that each node in the BST has a reference to its parent node....
3
votes
1answer
53 views

Building nested dictionaries to dump it to .json later

I am looking for some way to improve my code. It works but it doesn't look good and I am almost sure that lot of Best Practices rules are violated. The ...
1
vote
1answer
75 views

(Leetcode) Freedom Trail

I would like to know whether I could make my solution to this challenge shorter and more efficient. Below is the description of the challenge (this is a Leetcode problem) - In the video game ...
3
votes
1answer
48 views

Interactive command-line binary to decimal converter

Is this the most efficient way to write this piece of code? Is there a better way of handling errors inside of a while/for loop, instead of calling back to the original function? I have tried using <...
9
votes
2answers
110 views

Extract Information from Egyptian National ID

I did a script to extract information from the Egyptian national ID, e.g. national id is 14 digit ex(29501023201952). It could divide as described below: ...
3
votes
2answers
48 views

Functional Programming Hangman Practice

Recently, I have been trying to improve my functional programming skills and understanding. While at work today, my coworkers and I were playing Hangman in a group chat. I thought of a program that ...
2
votes
1answer
40 views

(Leetcode) Perfect Rectangle

This is a Leetcode problem - Given \$N\$ axis-aligned rectangles where \$N\$ \$>\$ 0, determine if they all together form an exact cover of a rectangular ...
5
votes
4answers
397 views

Printing Pascal’s triangle for n number of rows in Python

I have written a program that takes a number n and prints Pascal's triangle having n number of rows. Here is my code - ...
6
votes
1answer
52 views

Get nearest major city of an image (using EXIF GPS data)

I am writing a program that will take images in a folder, get the GPS Coordinates (from the EXIF data), then return the closest "major city". (I define a major city as one with an airport, so ...
2
votes
2answers
44 views

Appending multiple file loads in Python

I am fairly new to python, been coding in it for about a year or so. My company is switching from using SAS and a Netezza database for some of our data management. In order to access certain ...
3
votes
0answers
95 views

Converts audio files to fixed size chunks and the chunks to spectrogram images

This code takes in input as audio files (.wav or .WAV) and divides them into fixed-size (chunkSize in seconds) samples. Then these chunks are converted to spectrogram images after applying PCEN (Per-...
4
votes
1answer
35 views

JSON from SQL Server: Reduce lists of single dicts to list of values

SQL Server 2016 introduced some JSON features, but they're far from robust. As far as I can tell, there's no way yet to output a simple array; everything must be in ...
0
votes
1answer
108 views

Automate the Boring Stuff - Collatz Exercise

I wrote the following code for the Collatz exercise: The Collatz Sequence Any feedback is appreciated. Write a function named collatz() that has one parameter ...
0
votes
1answer
57 views

Python decorator to support static properties

Classes in Python do not have native support for static properties. A meta-class can rather easily add this support as shown below. Are there any problems programmers might experience if they use this ...
10
votes
2answers
135 views

Multi Key dictionary implementation

Description I had to create a dictionary structure where one value can be referenced by several keys. For example the keys a, b...
4
votes
1answer
86 views

The Dungeon game

This is a Leetcode problem - The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our ...
4
votes
2answers
56 views

My Hangman game in Python

I've been trying to practice more Python recently so I decided to try and make different simple text-based game programs. I'd hope anybody could help me see how to make the code neater or more ...
3
votes
2answers
121 views

(Leetcode) Escape a large maze

This is a Leetcode problem - In a 1 million by 1 million grid, the coordinates of each grid square are (x, y) with \$0\$ \$<=\$ ...
3
votes
0answers
60 views

Fast prime generator

I wanted to test my performance optimizing skills, and so wanted to find how fast I could get the first \$n\$ prime numbers. I limited myself to only the standard library, as I'm sure ...
2
votes
0answers
79 views

(Leetcode) Longest consecutive sequence in Python

This is a Leetcode problem - Given an unsorted array of integers, find the length of the longest consecutive elements' sequence. Your algorithm should run in \$O(n)\$ complexity. ...
4
votes
2answers
73 views

Groupby count, then sum and get the percentage

I wrote this code. It works, but I think there is a more elegant and Pythonic way to this task. Groupby and count the different occurences Get the sum of all the occurences Divide each occurrence ...
4
votes
0answers
28 views

Asynchronous Stripe API and aiohttp parameters formatting

I'm testing the Stripe payment API. I couldn't find a Python wrapper that provides asynchronous requests so I'm writing one. My first goal was to implement the async equivalent of ...
2
votes
0answers
61 views

Bursting Balloons

This is a Leetcode problem - Given n balloons, indexed from 0 to n-1. Each balloon is ...
5
votes
1answer
114 views

Create mosaic task

I tried to apply for software engineer - intern with this task, and there is no reply since I sent it, so I guess I failed. Can you give me a direction in what way I should improve my code? Task: The ...
5
votes
2answers
109 views

(Leetcode) Minesweeper game

This is a Leetcode problem - Let's play the Minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' ...
12
votes
1answer
1k views

Print the string equivalents of a phone number

Task Old mobile phones had the ability to type characters by pressing a number. The letter a could be typed by pressing 2 once. ...
6
votes
3answers
277 views

Version 2 - print new even-length arrays from two arrays

This is an update of the code for my previous post (which has now been removed as this code is more efficient and accurate) for the GeeksForGeeks task. Task outline Given two arrays, print all new ...