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
22
votes
4answers
7k views

Sieve of Eratosthenes - Python

I've been doing a lot of Project Euler lately and just wanted to make sure my implementation was as good as it could be. Does anyone have any suggestions to speed this up? ...
6
votes
3answers
2k views

Efficiency of Project Euler problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, ...
14
votes
2answers
4k views

Evaluating arithmetic expressions

I have written some simple code for evaluating expressions. However, I am not sure how well I am following conventions (this is my first time trying to). Specs for problem: All binary operators (+, -...
5
votes
2answers
2k views

Generating frequency tables based on CSV dataset

I am working on a project which crunches plain text files (.lst). The name of the file names (fileName) are important because I'...
3
votes
1answer
120 views

Abstract graphing-and-timing functions

I like to use timeit to measure performance of small, and sometimes big, functions. However it can be uncertain as to what the 'actual' time to execute the function ...
15
votes
3answers
4k views

Number of Islands in a 2d grid

Recently, I've solved this "Number of Islands" problem on LeetCode, the solution was accepted by the LeetCode OJ. Problem Description Given a 2d grid map of '1's (land) and '0's (water), count the ...
11
votes
3answers
2k views

RattleHiss (fizzbuzz in python)

This is an iterative review. The previous iteration can be found here. The next iteration can be found here I've now been programming in python for all of 4 hours. At 70 lines it's rather verbose ...
8
votes
2answers
766 views

CodeFights: Pipes game

Description Carlos always loved playing video games, especially the well-known computer game "Pipes". Today he finally decided to write his own version of the legendary game from scratch. In ...
12
votes
3answers
2k views

PyDOS shell simulation

I have a big project called 'PyDOS', written in Python 3.4, and it's going very well. Post your answers of anything that could make it look cleaner. ...
10
votes
2answers
20k views

Pretty-print Pascal's triangle

...
3
votes
2answers
205 views

Sequence processing problems

Problem 1: Sum the even numbers for the first n fibonacci numbers Solution: ...
11
votes
2answers
127 views

“Drone Racer” now shipping in your local area

This question is a follow-up of this one; where I present a software to plan and manage drone races. I might come with a new question about the SQL part in a few days as well. The code can still be ...
9
votes
2answers
725 views

Decoding grayscale PNG and performing Prewitt operator for edge detection

I'm a hobbyist programmer. What I try to do here is to read 8-bit grayscale PNG file. Then unfilter it. (That caused a headache). And after that perform Prewitt operator for "edge detection". I know ...
7
votes
2answers
210 views

SQL Query generator, round 2

This is the second round of reviews. The first round can be found in this question. This is a project I have been working on. This is one of my first experiences with Python and OOP as a whole. I ...
6
votes
2answers
854 views

2 player dice game, where even total gains points and odd total loses points NEA task computer science

This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points if it is odd, they lose 5. If there it is a draw after five rounds then the both users ...
5
votes
2answers
63 views

E-commerce scraper needs shortening

How would I go about shortening this code? I'm sure there's a smarter way to write the code. It's working fine, it's just ugly. It is a way to scrape the number of items on an e-commerce site. <...
5
votes
1answer
879 views

Python Port Scanner 2.0

A few months ago I put up a port scanner for review. Now, I've updated it with some new Python knowledge and integraing the feedback I got. Some things I specifically think might be wrong with it or ...
5
votes
1answer
452 views

Assigning sentiment to each tweet - Twitter trend

Below assignment is taken from here. Introduction In this project, you will develop a geographic visualization of twitter data across the USA. You will need to use dictionaries, lists, and ...
5
votes
2answers
2k views

Method and class method debugging decorator

A little while ago in The 2nd Monitor, me and @Phrancis were talking about Python and debugging, and the topic of function decorators came up with this message: Ethan Bierlein: You could even build ...
3
votes
3answers
3k views

Change filename of Excel-files based on the content of a cell

I have hundreds of Excel-sheets looking something like this: I can't use the actual sheet, and not the exact document numbers, since they are confidential. The name of the files are something like ...
3
votes
1answer
153 views

Stable reversed Tartaglia's triangles

Inspired by Minimising the triangle I am writing a fully tested program to solve the following problem: A triangle needs a good foundation. Every row in the triangle is derived from the sum of the ...
2
votes
1answer
3k views

Return path between graph nodes using depth-first search

This code is meant to implement a Graph class which has a method that returns a path between 2 nodes using depth-first search. I'm doing this to improve my style ...
15
votes
2answers
1k views

ECDH implementation in python

I wrote an implementation of elliptic curve Diffie-Hellman key exchange in python. I would like to know if I could make it faster, cleaner or more secure: ...
11
votes
2answers
1k views

Memoizing decorator that can retry

I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional ...
10
votes
1answer
1k views

Merge n sorted iterators

Over the weekend I was curious about efficiently merging multiple sorted iterators together, and for them to be in sorted order. This is quite like a challenge on HackerRank: You’re given the ...
9
votes
1answer
6k views

Creating truth table from a logical statement

This code creates a truth table from a statement in logic. The statement is input as a string, and it is identified as a tautology if it is true for all true and false combinations of the variables. ...
8
votes
1answer
3k views

Equation parser and solver

I wrote this equation parser and solver, I feel like it is well documented and tested: ...
5
votes
1answer
133 views

Arabic language lesson program

The program I have been working on has been developed almost exclusively as "train-of-thought" style code. Things happen linearly (for the most part) thru the code. The goal of the program is to house ...
5
votes
2answers
4k views

Print initial letter of an entered name

Just started learning python and I'm solving some beginner problems. I wrote a solution for a question without any edge cases like user not entering anything, entering numbers etc.: Question: Write ...
4
votes
1answer
393 views

Improving time complexity of finding the longest palindrome in Python

The Longest Palindromic Substring challenge from InterviewBit: Given a string S, find the longest palindromic substring in S. where a "substring" must be contiguous, and in case of ties the first ...
3
votes
1answer
128 views

Python3 Stack implementation with List built-in - Round Two

Previous code is available at Python3 Stack implementation with List built-in, this is a second-round review after I made alterations. Once again, let's review my Stack implementation, with built-in ...
3
votes
0answers
1k views

Breadth-first search: traditional and bidirectional in Python - follow-up

I have refactored the version of the previous (and initial) iteration according to the answer by alexwlchan. As a reminder, this snippet compares breadth-first search against its bidirectional variant....
3
votes
0answers
62 views

Simple General Purpose Parser Implementation

This is an implementation of a general Purpose Parser/Matcher that can operate on any input stream of objects and will return all possible combinations. In this case I do not value performance that ...
2
votes
1answer
218 views

Multifunction sprite class for pygame

I've written a class that allows me to easily create sprites on the screen, and then do things like: setting an image or an animation; move the sprite as a platformer or as a top down game; and test ...
1
vote
1answer
57 views

Project Euler 34 # Digit Factorials in Python

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not ...
-1
votes
2answers
2k views

Filter a list with given predicate - python [closed]

For the following question, the function • should mutate the original list • should NOT create any new lists • should NOT return anything Function that do not create new lists are ...
13
votes
4answers
22k views

Simple text RPG in Python

I am trying to teach myself to code using Python. The following is the first real program I have written from scratch. I feel that it is messy and in need of improvement, but I am either unsure of ...
6
votes
1answer
47k views

Bank ATM program in Python

For homework, I have to code a program in Python that effectively simulates a bank ATM. ...
41
votes
3answers
2k views

We'll be counting stars

Lately, I've been, I've been losing sleep Dreaming about the things that we could be But baby, I've been, I've been praying hard, Said, no more counting dollars We'll be counting stars, yeah we'll be ...
25
votes
5answers
4k views

Fishing simulator

I'm new to Python, for a school project I created a "fishing simulator". Basically, it is a use of random. I know that my code is repetitive towards the end, but I don't know how to simplify it. <...
9
votes
5answers
43k views

Simple Rock, Paper, Scissors in Python

I have looked at many different approaches to this game online, but as someone who isn't very experienced with Python, I may not be aware of what others are doing right. ...
16
votes
1answer
373 views

Warhammer: How many of my attacks will succeed?

Me and a couple of mates sometimes play a game called Warhammer. When playing the game you have options of what each model attacks. This can lead to situations where you know if you shoot with 100% of ...
10
votes
5answers
53k views

Python username and password program

Can the following code be simplified? I think that the program that I have created is very excessive and quite slow. The program runs fine, but I would like to understand if this could actually be ...
7
votes
4answers
13k views

Fibonacci sum with memoization

Problem: Using the recursion approach, find a Fibonacci sum without repetition of computation. ...
6
votes
3answers
631 views

Scraping a webpage copying with the logic of scrapy

Today, while coming across a tutorial made by ScrapingHub on Scrapy about how it usually deals with a webpage while scraping it's content. I could see that the same logic applied in Scrapy can be ...
37
votes
4answers
5k views

Beheading of knights, who survives?

We have a round table of n knights, where n is some positive integer. These have failed to satisfy the expectations of the mad ...
33
votes
3answers
2k views

Bush Wanderer - code intended for teaching

I am teaching computing to an AS class and this was their assignment: Bush Wanderer Task 1 Create a 5x5 grid of hashes(#) where the player is an ...
24
votes
4answers
2k views

Translating from English to Entean

I wrote a python script that converts English to Entean language from an anime called "The Devil is a part timer". I am sloppy at coding and know that the script can be made better. In the anime, the ...
12
votes
1answer
1k views

Flatten an array of integers in Python

The goal is to flatten an array of nested arrays of integers. For example [1, [2], [3, [4]]] should return [1, 2, 3, 4] I'm ...
12
votes
1answer
669 views

Let's read a random Goodreads book in an optimal way

I have made the following program to gather data on random books from Goodreads, via their random books feature. ...