# 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.

3,309 questions
Filter by
Sorted by
Tagged with
2answers
92 views

### Tkinter program to teach Arabic

I am writing a lesson-based program to help teach friends and family the basics of Arabic. The program consists of different sections (letters, numbers, personnel pronouns, etc.) and each of those ...
1answer
53 views

### Python and FileIO

I've written a bunch of functions that deal with handling files on a Linux system. I'm looking for critique on the whole class, in particular: Exception handling Efficiency Style I'd also like to ...
1answer
66 views

### All-Python implementation of n-dimensional convolution

To better understand how discrete finite convolution works (read educational purposes) I wrote an all-python implementation of the convolution function. The idea was for it to give the same output as <...
1answer
28 views

### Search for strings in a list that have > 90% similarity

Explanation: I am working on String comparison in which I want to cross-compare the list of the same input string. For the same string, I am continuing the loop but if a single string will have ...
2answers
82 views

### Project Euler # 74 Digit factorial chains in Python

The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145: 1! + 4! + 5! = 1 + 24 + 120 = 145 Perhaps less ...
0answers
47 views

### Trapping Rain Water in Python

This is from Leetcode My solution is based on Python 3. It was faster than 90% of solutions on Leetcode, but used too much memory. Please what makes this memory hungry? How can I make this more ...
1answer
56 views

### Project Euler - Problem No.5 - Smallest multiple

Here's the problem at hand: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly ...
0answers
22 views

### Using metaclass to decorate derived classes to be attrs classes

I am currently developing a framework to facilitate writing controller programs for scientific instruments. I use attrs extensively in the internal parts of the ...
2answers
49 views

### Read coordinates from many files and calculate polygon areas

My goal with this snippet is to create an array of coordinates which in turn is a tuple of 68 elements, area and modified area array for all 10k elements and assign it to the ...
0answers
504 views

### Function to sum values of most significant digit contained

ABOUT For each subsequence, look at its position in the original decimal representation of $x$. Let's say that the most significant digit it contained was the $e$-th digit, where $e=0$ ...
1answer
51 views

### Solution to LeetCode Next Greater Element Ⅰ in Python

This is my solution to LeetCode's "Next Greater Element Ⅰ": You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater ...
0answers
39 views

### Determine the hyper-parameters of an Approximate Bayesian computation

I created my own Approximate Bayesian computation algorithm in Python 3 and I try to find the best hyper-parameters for it but it is really slow. This question is not about the math involved in it. ...
3answers
4k views

### Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) …1748 Euler

I wrote this code to show that my reddit post is correct. After the first two terms, the signs are determined as follows: If the denominator is a prime of the form 4m − 1, the sign is positive; if ...
2answers
95 views

### Parking Lot Object Oriented Design Python

I own a parking lot that can hold up to 'n' cars at any given point in time. Each slot is given a number starting at 1 increasing with increasing distance from the entry point in steps of one. I want ...
1answer
58 views

### Project Euler - Problem No.4 - Largest palindrome product

according to the problem: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made ...
2answers
50 views

### Tic-Tac-Toe code using Python with Tkinter

`I made this Tic-Tac-Toe game first, by using user input in the console here: https://pastebin.com/6zLjrWcf , and now new and improved using Tkinter: ...
2answers
47 views

...
1answer
67 views

### Find the number of pawns available for a rook to capture

I find that very very often with matrix questions, the traversal and comparison part of the solution is very verbose and repetitive. For example, this code (written for a coding challenge) to find ...
1answer
2k views

### Raindrops in Python

There's this simple coding challenge that feels like a twist on FizzBuzz. Your task is to convert a number to a string, the contents of which depends on the number's factors. If the number has 3 ...
2answers
52 views

### Project Euler - Problem 3

The description of the problem is: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Here is my solution: ...
1answer
40 views

### Short function to remove unnecessary whitespace

I have a function consisting of one line of code: def trimString(string): """ Remove unnecessary whitespace. """ return re.sub('\s+', ' ', string).strip() ...
2answers
79 views

### Project Euler # 67 Maximum path sum II (Bottom up) in Python

This is Project Euler #67: Maximum path sum II: By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 ...
1answer
24 views

### Return timeframes relevant to just-elapsed time period (financial/trading context)

I am writing trading software, and have written this utility function. Its purpose is to return a list of timeframes relevant to the just-elapsed time period. "Timeframe" here means bar or candle ...
0answers
25 views

### Form deserializer for Python Flask

I've started working on a small Flask project for no real reason other than fun, and pulled myself back on form validation. I realize that there are existing libraries like WTForms, but wanted to try ...
1answer
39 views

### Python Tkinter login GUI with database

I created a simple login program that works how I wanted them to work. I separated the GUI and database codes into two different python files. I named the files as login.py and dbaseManip.py. The ...
1answer
77 views

### Footwear scraper

I've done this parser to scrape all footwear data, but I don't know if it is good to use OOP in this case. Can you please check this out and give me the strongest feedback? I'm working on improving my ...
1answer
49 views

### Project Euler # 55 Lychrel numbers in Python

If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 That is, ...
2answers
85 views

### Project Euler # 54 Poker hands in Python

In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest value card. One Pair: Two cards of the same value. Two Pairs: ...
0answers
91 views

### Not so Excellent Knight's Tour

Note: This is part of a set of demo applications I'm writing for colleagues to show we're not limited to VBA when dealing with Excel. Considering our IT challenges (no admin on-site & no local-...
0answers
44 views

### Linny: Continued Language Development

A previous question regarding Linny exists here. After a wonderful response on my previous question regarding my developing programming language, I worked on it for a couple days, and am returning ...
1answer
56 views

### Updateable Priority Queue

I've implemented an updateable priority queue as a part of implementing some single-source-shortest-path algorithms (Dijkstra, BF). I'm relatively new to Python. ...
2answers
33 views

### Consolidating a dictionary from nested dictionary

Currently learning from "LPTHW - Zed Shaw" and "Automating the boring stuff". There is a nested dictionary of the type ...
2answers
56 views

### Project Euler # 56 Powerful digit sum in Python

A googol ($10^{100}$) is a massive number: one followed by one-hundred zeros; $100^{100}$ is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits ...
1answer
112 views

### Linny: An Interpreted Programming Language

There is a follow up question here. I've undertaken the project of creating my own programming language, Linny. It's a very, very simple language, with only variable creation, variable changing, and ...
3answers
1k views

### Determine if a triangle is equilateral, isosceles, or scalene

I've been fiddling around with some easy code challenges and there's one about determining if a triangle is equilateral, isosceles, or scalene. I've come up with a working solution, but I feel this ...
1answer
49 views

### Project Euler # 53 Combinatoric selections in Python

There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In combinatorics, we use the notation, 5C3=10. In general, nCr = n! / r! (n−r)!, ...
2answers
55 views

### Project Euler # 52 Permuted multiples in Python

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, ...
2answers
70 views

### Determine whether three sides form a valid triangle, and classify the triangle

This is a my first Python program, and whilst I am new to Python I would like to keep in good practice Below is a short program to work out what type a triangle is and if it makes a valid triangle ...
0answers
28 views

### Python script to import MySQL tables to PostgreSQL

I'm using the below Python script to port few table data from a remote server (MySQL database) to my data warehouse server (PostgreSQL DB), The script is working fine (I'm using foreign data wrapper), ...
1answer
21 views

### Optimising the BFS

The input graph to the bfs function is in the form of edge list representation. ...
1answer
47 views

### Traversing two trees until a common value has been found

I am traversing two objects that may share a common ancestor. To make the code small enough to show here, I have changed it into two dictionaries with values. As you can see, ...
0answers
28 views

### Invoking parallel threads of a nslookup command in python

I've written below python script just to invoke parallel threads of a command nslookup linux-host01 dns-server, i'm Just trying to flood the DNS Server ...
1answer
96 views

### Project Euler # 50 Consecutive prime sum in Python

The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred. The longest sum ...
2answers
63 views

### Caesar Cipher Guesser

I've written a Caesar Cipher in python (a more in-depth explanation is provided in the docstring at the top of the program). At first, it was supposed to just be the cipher, but I expanded it to have ...
0answers
18 views

### Grouping by on Pandas df with focus on performance

I am doing a group by on a subset of a dataframe. I am working with 9m+ rows atm, subject to sharp increase. I tried different approaches already and wanted to know if i could squeeze a bit more ...
1answer
223 views

### Project Euler # 49 Prime permutations in Python

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are ...
1answer
64 views

### Project Euler # 48 Self powers in Python

The series, $1^1 + 2^2 + 3^3 + \ldots + 10^{10} = 10405071317$. Find the last ten digits of the series, $1^1 + 2^2 + 3^3 + \ldots + 1000^{1000}$. ...
1answer
45 views

### File compressor

I have written a file compressor in python. The program generates a file filled with sequences of the same character with a random length, and compresses that file. I would like feedback on code ...
2answers
62 views

### Grouping sorted coordinates based on proximity to each other

I created an algotrithm that groups a sorted list of coordinates into buckets based on their proximity (30) to one another. Steps: Create a new key with a list ...
3answers
77 views

### Project Euler # Triangular, pentagonal and hexagonal in Python

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle: $T_n=\frac{n(n+1)}{2}$ 1, 3, 6, 10, 15, … Pentagonal: \\$...