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
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 ...
3
votes
1answer
356 views
5
votes
2answers
102 views

Geometry table for use in regexes

I have been teaching myself Python 3. I watched a video on YouTube entitled "stop writing classes". The Gtable class doesn't even have an init function, so I can't help but wonder if I should have ...
3
votes
1answer
859 views

Write and control Perlin noise for 1D

I'm reading this tutorial and it's the first time I try something this new. Here is my attempt: ...
5
votes
2answers
4k views

ASN.1 BER Encoding and Decoding

I have a project (ldaplib) I am working on that needs to do ASN1-BER decoding and encoding. The function I have for the decoding portion is slightly more complex but neither are all that complicated. ...
6
votes
1answer
3k views

Segment tree in Python3

I've implemented a Segment Tree in Python3: ...
6
votes
1answer
70 views

Determining the least-accurately known physical constants

So, I thought I'd do this using scipy.constants: ...
6
votes
2answers
167 views

Searching for files in a specified directory

I am currently writing a program that allows me to search for files in a user-specified directory. My current code is as follows: ...
4
votes
1answer
108 views

Installing Mods With Python (v 2.0) [closed]

My original code is here. I made some changes to it based on your suggestions, but then I lost my flash drive and had to redo it. I have a suspicion that my second version was better than this one, so ...
7
votes
1answer
2k views

Implementation of SAT (Separating axis theorem)

A project I was working on required the usage of the Separating Axis Theorem to detect collisions between two convex polygons in real time. So I implemented a basic class (...
12
votes
2answers
2k views

Python Port Scanner 2.1

I made lots of changes to the script presented in my previous question. I was tempted to edit that one with the new code, but it would invalidate @200_success's helpful answer. It was also ...
5
votes
1answer
883 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 ...
8
votes
2answers
204 views

Python script to test music sight reading

I decided to write a program to test music theory, and, while it would've been much easier for me to make it elegant and perfect in Java, I thought I'd take the opportunity to get more familiar with ...
6
votes
1answer
48k views

Bank ATM program in Python

For homework, I have to code a program in Python that effectively simulates a bank ATM. ...
6
votes
1answer
2k views

Should I put python3 argparse filetype objects in a contextlib stack?

I just read the Lib/argparse.py code (class FileType) on http://hg.python.org/cpython/file/default/Lib/argparse.py. File objects are opened without the with statement. For safe file opening/closing, ...
8
votes
2answers
334 views

Wrapping my head around generators

I am going on with refactoring my code base while migrating from Python 2 to Python 3. I am using generators to make reusable components this time as I am more comfortable with them this time then ...
5
votes
1answer
475 views

Increasing readability of maximum path sum algorithm

I had written a solution for Project Euler problem 18 in Python 3. It is good in its efficiency but the problem is the readability and I think reuse. The algorithm used is that at every iteration ...
2
votes
1answer
1k views

Calculator for finding mass

I've been trying to create a calculator to find mass using any and all known equations. The program will also return the steps used to find mass so the user can 'check their work' on physics ...
7
votes
2answers
933 views

Dynamically generating Strings (or other variables)

I've got a Python script which is meant to launch several other shell scripts with the appropriate setup and parameters. I construct the file paths from other variables so that it's easier to change ...
10
votes
4answers
4k views

Suggestions for a Dungeons and Dragons-like game

This game is similar to a Dungeons and Dragons game. How could I improve the efficiency of the program? For example, where can I add functions, records etc? This is for a school Controlled ...
14
votes
2answers
2k views

Drink order program

I'm looking to improve my code to make it more efficient, such as shortening it but continuing to gain the same output, or to add some more complex functions into the code. ...
3
votes
1answer
840 views

Time optimization of counting shifts in insertion sort

Is there any way of counting how many shifts would it take to count shifts while doing insertion sort? This is a Hackerrank problem. Here's my solution, but it takes more than 16 seconds. ...
7
votes
2answers
6k views

Sherlock and The Beast

I have recently written the program for the Sherlock and The Beast' HackerRank challenge. That's working fine, but the problem is that it takes too much time if a big number is given as a input. I ...
10
votes
2answers
20k views

Pretty-print Pascal's triangle

...
0
votes
1answer
1k views

Calculating Leibniz of Pi [closed]

I have this Python program for calculating Leibniz of 'pi'. I am not able to shorten it more. Can anyone here optimise/shorten it? ...
3
votes
1answer
515 views

Verlet integration movement - doubt for on_key_press() methods

Based on my understanding of Verlet integration I tryed to use it over my Euler method to move my character in a 2D space. I will put only the neccessery code, but if anything else is needed I will ...
4
votes
1answer
384 views

Modified BFS code optimizations

I need some help reviewing this code in terms of making as fast as possible. This is a modified version of BFS that does quite a bit of processing on the side. Use case: I have a large graph (...
10
votes
1answer
316 views

Produce bitcoin private key from 31 playing cards

I've written some Python code to generate a random hexadecimal string using 31 playing cards drawn without replacement (so no card appears more than once). This is sufficient to provide more than 160 ...
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? ...
15
votes
2answers
2k views

Condorcet voting method in OOP Python

I'm currently learning Python and having a great time so far (coming from PHP, I have a feeling of suddenly seeing the light). At the same time, I'm studying voting algorithms. So, for training ...
6
votes
3answers
1k views

Optimization for SQLite result set parsing

I am retrieving information from an SQLite database that gives me back around 20 million rows that I need to process. This information is then transformed into a dict of lists which I need to use. I ...
11
votes
3answers
706 views

Installing “mods” with Python

A little disclaimer: you're going to have a field day with this. It's horrible. Looking at it makes me want to vomit, and don't ask me to explain it, because I've long forgotten what I was thinking ...
4
votes
1answer
228 views

Cutting strings into smaller ones based on specific criteria

I've got this largish (for me) script, and I want to see if anybody could tell me if there are any ways to improve it, both in terms of speed, amount of code and the quality of the code. I still ...
6
votes
1answer
1k views

Hooking with Python3 Decorators

I wrote this prototype after reading the Wikipedia article on hooking. I didn't bother to read any of the code examples listed there because, well, I just didn't. I don't have a good excuse. The ...
7
votes
1answer
155 views

More efficient way of removing line indices?

After profiling my current script I've found that nearly 100% of the run time (and I'm not surprised) comes from the following function: ...
3
votes
1answer
160 views

Twirling cursor

I'm writing a twirling cursor, which is a cursor that twirls in place in the console. In Forth, this takes just 3 lines, whereas in Python3 I have this: ...
7
votes
3answers
2k views

Simple MPG calculator in Python

I am a self taught coder taking a Programming Fundamentals class to work towards a degree. It's based on Python, which I'm not as familiar with as other languages. I added error handling like I would ...
10
votes
2answers
9k views

Optimizing solution for Project Euler Problem #23 (non-abundant sums)

Project Euler Problem 23 asks: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 ...
5
votes
1answer
3k views

XLSX writer implementation

We have multiple scripts which write into XLSX with the same format, into a different format or slide variation. I am trying to write an API which saves time for other programs, but I need input on ...
7
votes
4answers
155 views

Record Cataloging Program

I made a simple program to catalog some old records I have. It seems a tad redundant in the searching function. Does anyone know what I can do about that? ...
2
votes
1answer
466 views

Python Hangman feedback

Just looking for some feedback on a hangman script. It works perfectly fine; I'm just trying to master the Python language, and the best place way to get better is to ask the true masters! ...
3
votes
1answer
328 views

Python data massager

Below is a pretty simple Python script to ingest some data, massage it as necessary, append a column, sort it, and then write it back to another file. Still learning all the Python best practices and ...
6
votes
2answers
7k views

Newton's method to solve cubic equations

I have used the Newton-Raphson method to solve Cubic equations of the form $$ax^3+bx^2+cx+d=0$$ by first iteratively finding one solution, and then reducing the polynomial to a quadratic $$a1*x^2+b1*x+...
6
votes
1answer
5k views

Tkinter file searching program

This is my first relatively big program. First it shows an askdirectory() screen to get the path. It gets all subfolders of that path and appends them to a list. It ...
3
votes
1answer
2k views

Python converter: number-to-English - Project Euler 17

So I wrote this function to convert a given number to its interpretation in the English language as part of the Project Euler exercises. It works fine, but I sense that it's rather sloppy and ...
6
votes
3answers
684 views

Performance of modular square root

Here's Project Euler problem 451: Consider the number \$15\$. There are eight positive numbers less than \$15\$ which are coprime to \$15\$: \begin{align*} 1, 2, 4, 7, 8, 11, 13, 14. \end{...
3
votes
1answer
19k views

Reading columns and rows in a .csv file

I have some data in a .csv file, which looks roughly like this: ...
9
votes
2answers
9k views

Python Port Scanner

This is only my third Python script. Be brutal with me. Any tips, tricks, best practices, or better usages would be great! ...
1
vote
1answer
5k views

Fastest way for working with itertools.combinations

I need to speed up the function below: ...
4
votes
1answer
375 views

Partial data reading implementation

I'm trying to learn Python and am working on a simple Tiled Map Format (.tmx) reader as practice. So as to not post too much code at once, I'm only publishing the ...