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
1answer
620 views

Decision tree for binary classification

I want to become a good Python programmer and so I'd like to know what in my code practices I can improve. Overall I feel like a pretty solid programmer but writing this code felt very "Java" so I am ...
3
votes
3answers
2k views

Primality test using recursion

For the given below exercise: Here is one method to check if a number is prime: ...
3
votes
1answer
1k views

Square spiral matrix

I've written a Python script to generate the closest square spiral matrix to a given number. I'm new to code reviews as a practice, and I'm interested in ways to improve. Please suggest improvements ...
3
votes
1answer
103 views

Factors sieve optimization

I've written a more powerful version of the Sieve of Eratosthenes, this Sieve returns the number of factors of all the numbers below the limit.Sadly the running ...
4
votes
2answers
738 views

Function returning higher order function

For the below given exercise: Define a function cycle which takes in three functions as arguments: f1, f2, f3. cycle will then return another function. The returned fuction should take in an ...
4
votes
2answers
3k views

Amazon web scraper

I am trying to improve my programming and programming design skills (poor at the moment). I created a small Amazon scraper program. It is a working program. I would be very grateful if you could ...
5
votes
3answers
334 views

Conway's Game of Life (follow-up)

I asked for a review of my code, and after making the suggested changes I feel that now the OOP version is clearer in its meaning and overall the code looks cleaner. ...
7
votes
1answer
8k views

Conway's Game of Life in Python3

I've implemented Game of Life in Python for a programming problem, in two different versions: one is a simple script and the other uses a class with a dictionary to initialize the various parameters. ...
8
votes
3answers
819 views

Soundcloud to CSV File

This program connects to Soundcloud and turns the supplied username into a CSV file with the user's like list. The code accomplishes this although it looks rather messy and was wondering what I could ...
4
votes
1answer
74 views

If a message is there, but you cannot see it, is it really there?

I have created a space encoder program, because it is fun to generate invisible messages. (This programme is not cryptographically secure, it is just for fun) ...
2
votes
1answer
250 views

Dumping fields from Python objects

I am writing a small class that has one method: get_state. It is parameterless and returns a dictionary of all the names in self (look in its dict) that are not ...
0
votes
2answers
4k views

Using recursion to count nodes in a binary tree, test equality of linked lists, and find extrema of a linked list

I am working with a some small functions to test recursion. I am fairly new to Python and am wondering if there is a cleaner way to get the job done. ...
1
vote
3answers
847 views

Counting the frequency of letters in a string slices

While preparing a solution for the CodeChef - magic tricks, an easy question about counting the frequency of given character from the string slice, I came up with the following solution: ...
11
votes
2answers
12k views

ASCII-fication of playing cards

I am making a small Blackjack game in Python 3. The part of the code I am unsure about is that which allows me to print nice ASCII versions of the card. ...
7
votes
3answers
18k views

Manipulating CSV files to regular text file

At my job, often I have to manually convert *.csv Files structured like: number,number\n number,number\n number,number\n ... To a regular *.txt file with the ...
4
votes
1answer
2k views

Removing graph nodes of a specific type and with exactly two neighbors

I am working with an undirected, weighted graph. It contains two types of nodes, called "A-type" and "B-type". I am starting with a set of tuples of the following ...
4
votes
1answer
1k views

Dictionary with restricted keys

I'm currently building some software that works with systemd unit files, and I've been trying to improve how we construct the unit files. This is all running in Python 3.4 This first block is the ...
3
votes
2answers
3k views

Failing fast by raising an exception with a custom message

This is a script that utilizes lazy exception throwing. What I do is decorate a function that might throw an exception to throw an exception with a formatted string. ...
4
votes
1answer
1k views

Latitude/longitude waypoint distance calculations, crosstrack, VMG, ETA, etc

I'm in the process of a complete re-write of a stagnant and ill-conceived project. I would like some feedback on the following Python 2.7-3.4 code, before I go any deeper into it. I would hope it is ...
4
votes
1answer
76 views

Converting xy coordinates to theta without discontinutities

This one is, or rather, should be, fairly simple. I have a list of tuples of XY positions, and am trying to pull out angles relative to the origin from it. However, unlike ...
4
votes
3answers
2k views

Functional programming approach to repeated function application

Control like if..else and while If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the \$n\$...
8
votes
3answers
2k views

Adding two roman-numeral inputs

This is the first coding class I've taken and I'm not getting much feedback from the instructor. The function of this program is to take two roman numeral inputs, convert them to arabic, add them ...
3
votes
2answers
87 views

Factorisation code running slow

I'm still in the process of learning Python and am doing some of the Project Euler problems. I have made a factorisation algorithm that works; however, it runs really slowly, and I'm not too well-...
3
votes
2answers
896 views

Summation and product functions using functional paradigm

Below is the problem: Show that both summation and product are instances of a more general function, called accumulate, with the following signature: ...
6
votes
1answer
2k views

CAPTCHA reader and maker

I've made some CAPTCHA reader and maker in Python using Tkinter. Do you know if it's possible to keep image and output files in "memory" not writing them on disc? Because right now everything is '...
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. ...
4
votes
1answer
132 views

Project Euler #10 in Cython

I'm trying to teach myself some Cython. To do so, I use Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. 2 Find the sum of all the primes below two million. My Cython ...
3
votes
1answer
636 views

Counting Lines and Sum of Lines

I have a small function that when passed a str that names a file that contains a program; it returns a 2-tuple with the number of the non-empty lines in that program, and the sum of the lengths of all ...
3
votes
2answers
5k views

Recursive functions for sorting

I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code: ...
5
votes
2answers
1k views

Functions with mutable and non-mutable named tuples

I am making some functions within a function for learning which when passed information about a named tuple: it returns a reference to a class object from which we can construct instances of the ...
5
votes
1answer
983 views

Flooring cost calculator

I've made a small program that calculates the cost of flooring for a given area based on the price per sqft and total sqft. I have only been programming for a few days now so I am sure that there are ...
0
votes
2answers
214 views

Two permutation iterators for classes in Python with and without a generator

I am just testing out a couple of small classes for learning purposes. Here is my current working code: ...
4
votes
4answers
343 views

Functions taking iterables: peaks, compress, and skipper

I am just testing out a few small functions for learning purposes: ...
6
votes
3answers
13k views

Hailstone Sequences in Python

For the problem given: Douglas Hofstadter’s Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle. Pick a positive integer \$n\$ as the start. If \$n\$ is ...
17
votes
2answers
282 views

Gimme some random passwords

pwgen is a nice password generator utility. When you run it, it fills the terminal with a bunch of random passwords, giving you many options to choose from and ...
5
votes
2answers
12k views

Disjoint-set data structure in Python 3

Inspired by this question, I decided to implement a Disjoint-set data structure in Python 3. I mainly followed this description for understanding the algorithm (but did not do the optimizations for ...
2
votes
1answer
166 views

Little command line video grabber

I made a little Python3 script to grab video clips from a website for viewing off-line later and would like your critique, advice, tips & tricks and/or learning resources to create better code. (...
1
vote
1answer
3k views

Expiring in-memory cache module

I needed a simple expiring in-memory cache module for a project I'm working on and I've come up with the following. My requirements for the cache module are: Be able to expire objects after certain ...
3
votes
1answer
91 views

Solution for puzzle 3d x 1d = 2d x 2d in Python

I wanted to resolve the puzzle from this link using Python 3. It works and gives me the correct value but I would like to know if it is possible to resolve this problem with a few lines or how I can ...
3
votes
2answers
5k views

Bag data structure (a set that can store multiple copies of items)

I am trying to make my class a bit cleaner, especially some of its methods like Count, __add__, ...
15
votes
1answer
337 views

Modeling a Mage character from nWoD, using Django

Goal Design a representation of a mage character from the World of Darkness RPG, as well their associated spells. Here is a visual representation of the schema. You can see it more closely on ...
2
votes
1answer
55 views

Python object modelling with ABCs

I'm modelling the core entities in a callcenter-related system that deals with Operators and groups ("pools") of them. While I've written some Python before, this is my first time building a larger ...
2
votes
1answer
1k views

Python decorator for optional arguments decorator

I want my Python decorators to have optional arguments and not be called when not necessary. The accepted answer in here doesn't accept named arguments, and I don't want to add boilerplate code ...
6
votes
3answers
6k views

Create SQLite backups

I have this script for creating SQLite backups, and I was wondering whether you'd have any suggestions on how to improve this. I was thinking that maybe it should create the backup ...
5
votes
2answers
761 views

Interleaving values from several iterables

I am new to Python and am trying to see if there is a cleaner way to write my code. The following code take iterables as parameter it produces the first value from the first parameter, then the first ...
4
votes
1answer
7k views

All-in-one number base converter

I coded this program as a challenge for /r/dailyprogrammer. Basically this program can convert any number from any base to another base including negative bases as long as the input is coherent. Did I ...
5
votes
1answer
1k views

Simple encryption based on MD5

I made a Python 3(.4.2) program that only adds classes and is meant to be imported. It allows the creation of files that store usernames and hashed passwords. It uses salting as well. It also can ...
3
votes
2answers
401 views

Project Euler #14 solution takes quite a long time

Can anybody give me suggestions for making it faster? (Project Euler #14) ...
3
votes
2answers
108 views

Python path-breaking script for use in R

R does not support line continuation as Python, and it's disturbing to have long file paths like /media/user/data/something-not-very-important-but-super-long/some-curious-secret-file.pdf and can't ...
2
votes
1answer
69 views

Books Algorithm Dealing with Square Digit Sums

A little context: Book has 411 Pages Read a random number of pages on the first day which is unknown Number of pages to read next day is the square of the sum of the digits of the page ...