Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

learn more… | top users | synonyms

-1
votes
0answers
8 views

Modular arithmetic brute-force congruence finder

My full code is running too slow. I do profile.run to my project and found out this function consumes alot of time. ...
3
votes
2answers
28 views

Calculate all subgroups of a cyclic group (group theory)

The task was calculating all subgroups of a cyclic group Z/nZ where n is the modulus and returning them as a list of lists. The ...
10
votes
2answers
243 views

Project Euler #22 - Names Scores

I programmed Problem #22 from Project Euler in Python. It works but I want to know if it really is pythonic enough. Using names.txt (right click and 'Save Link/Target As...'), a 46K text file ...
6
votes
3answers
98 views

Simple addition, multiplication, divison, and subtraction program

I made a post a couple of days ago asking if anyone noticed bad habits or thought of any suggestions: (First Hangman game) I've made 2 math programs just to make sure I got it all down pat. The first ...
4
votes
1answer
38 views

POJO class and large constructor

I have some dispute with a colleague. I work with some REST-service, from which I get always same type data. ...
5
votes
1answer
60 views

Simple 1-player Battleships game

This is my simple code for a Battleships game: ...
11
votes
2answers
252 views

Python review_generator

Given a Python file containing a Python script written with bad style, this script will output a review adressing its problems. ...
5
votes
1answer
60 views

.txt word-counter

I'm starting coding with Python (only able to use & create easy code!) and just created a word-counter. It reads a .txt file and enters the words in a dictionary with dict[word]="number of ...
6
votes
5answers
199 views

First Hangman game

This is my first ever program created after reading a book on Python. Do you have any suggestions for me? Anything that are considered bad habits that I should correct for my new project? ...
3
votes
1answer
52 views

Finding average word length in a given year

I have written a function which takes the year in question and words as a data which is a dictionary that maps words to the list of year/count. Now I am wondering how I can improve the code that I ...
3
votes
1answer
40 views

Determine all prime, palindrome string integers within a range

I have written a program in Python 3x to determine all the prime, palindrome string integers in the range of two given numbers. ...
2
votes
0answers
36 views

Python proxy class

I've coded my own proxy class in python. The aim is to have a different type() but otherwise behave as identical to the underlying object as possible. I'm wondering ...
2
votes
1answer
45 views

Making Tic-Tac-Toe winning check more efficient

My code works perfectly fine and I would just like to clean it up a little. From the research I've done, I cannot find anyone that used a multidimensional list to a game of TTT. I'm just looking for a ...
7
votes
4answers
350 views

Kaprekar's constant

I'm new to Python and as a first exercise, I've written a function (module?) to calculate Kaprekar's constant using Python 3. I'd like some feedback on whether this is Pythonic enough, and if I can ...
3
votes
3answers
790 views

Calculate highest prime factor very slow

Sometimes when I write a Python 3.x script with too many nested loops and some big values it just takes too long to give the answer. How can I optimize my code so that it runs faster, or where should ...
2
votes
2answers
95 views

Extended Euclidean algorithm and modular multiplicative inverse element

After my first exercise here is another. Again, this is exactly that: Exercise, which means that the output doesn't necessarily need to be beautifully formatted, etc. I probably have some variable ...
1
vote
2answers
49 views

Inserting e-mail subscribers into MySQL

I'm new to Python and I am learning database connections from here. This is the code I am using to insert e-mail subscribers into a table: ...
3
votes
2answers
95 views

Binary to decimal number converter

Here I am doing some exercises for my studies with Python. This is a binary to decimal number converter (currently restricted to that). These are the very first steps, so there is no error handling. ...
6
votes
3answers
158 views

Writing cubic sums a better way

I was asked the following problem: What is the smallest positive integer n that can be written as a sum of three positive cubes in at least 12 ways? Can this be coded better way such that it is ...
2
votes
2answers
77 views

Make a dict class from scratch in Python

Here's the API my teacher assigned: and here is what I came up with: ...
12
votes
6answers
2k views

Monte Carlo pi calculation

In order to learn the basics of Monte Carlo I calculated pi with it. I also wrote an explanation of the reasoning behind the code. Down here you can see the circle with random points that I simulated ...
0
votes
3answers
91 views

My take at ProjectEuler #17 - counting counting characters

I tried to tackle #17 problem on Project Euler: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are \$3 + 3 + 5 + ...
0
votes
2answers
51 views

Defining metaclass instance methods inside of the metaclass factory instead of the metaclass itself - flawed design?

I'm wondering if this is good design, or if the definition of the __init__, __call__, and ...
0
votes
1answer
35 views

Auto-update server

Yesterday and today I've been working on an auto-update system for a game project. I've just pushed the server-side script to the server, and it seems to work great. Since this is public-facing code, ...
1
vote
0answers
113 views

Calculate the average length of words in a phrase [closed]

I have a function avg_word_length(str) that takes a string and calculates the average length of the words. The input has to be cleaned up before the words can be ...
3
votes
1answer
70 views

Mergesort and validation

I have written an implementation of a Mergesort in Python3. An Ideone with the implementation is available. Any suggestions for improvement or any criticisms? ...
2
votes
1answer
60 views

Node2D and Node3D classes implemented using a shared decorator

EDIT: I have made another go at this using metaclasses here. I think it's a much better approach. I have the following classes. validator is a decorator that ...
1
vote
0answers
96 views

Real-time bitcoin data feed and storage using websocket framework

I'm trying to create data feed script for real time bitcoin data for OkCoin exchange using their websocket API (documentation) and a database manager for storing. There are two channels i am ...
3
votes
1answer
78 views

BK Tree implementation

I'm working on a system that can search for similar images. This involves being able to search by edit-distance, and as such I've implemented a special data-structure called a BK tree. Some notes ...
3
votes
1answer
79 views

Convert between two bases, each between 2 and 36

I'm doing some Python practice for fun and I wrote some code that converts between two bases. I'm thinking about expanding on this later, so the docstrings are pretty redundant from function to ...
3
votes
2answers
61 views

Eurovision voting order

Part of the Eurovision Song Contest is the voting process to determine the winner of the contest. Each country gives between 1 and 12 points to its 10 most favorite songs. When all the points have ...
2
votes
2answers
53 views

Collatz Conjecture in Python

The Collatz's Conjecture states that any number can either be halved (if it is even) or multiplied by three and added one to (if it is odd) and eventually reach 1. I was wondering if there was a more ...
6
votes
2answers
209 views

Command-line-based capacitance decoding

I am an amateur programmer and have just written a simple Capacitor Identifier mostly to practice. I have not had many people review my coding and thought this would be a good time to start. It is ...
0
votes
0answers
58 views

Longest increasing subsequence and common substring

I wrote a program that computes longest increasing subsequences and common substrings. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to represent a ...
6
votes
2answers
137 views

Caesar cipher with GUI

I have created a functional Caesar cipher in Python 3 and I have implemented a GUI using Tkinter. ...
4
votes
1answer
49 views

Kindergarten Garden challenge: ugly zip-group-flatten?

I wrote up a solution for the "Kindergarten Garden" problem on exercism.io. My class will be handed a string that describes two rows of plants. Each student (either in a pre-set list or given as ...
1
vote
2answers
81 views

Code to generate a dictionary from two lists

I created a script to perform a union on 2 lists: keys and words. I needed to create a dictionary from them. If there are more keys than words, missing words are replaced with "None". Any excess words ...
5
votes
1answer
114 views

Transpose a large matrix in Python3

I want to transpose this matrix input: 1.000 2.00 3.0 4.00 5.00 6.000 7.00000 8.0000000 9.0 10.0 11.0 12.00000 And get this output: ...
8
votes
2answers
120 views

List files in a directory

I have folder1 that contains other folders (which may contain other folders etc). This process stops at some point where a folder contains only files, and some of ...
1
vote
1answer
61 views

Simple backup script

I haven't done much Python in the past, so I was wondering if you could look over my code and make sure everything is up to snuff? I know programs that do this exist already, but I am having a ...
1
vote
2answers
45 views

Code for showing installed python packages/modules

Any comments about style (especially any "non-pythonic" code), performance, readability, etc would be much appreciated! I've tested this on CentOS and OSX 10.9. Works for Python 2.7 and 3. ...
3
votes
0answers
49 views

Python API for TreeStructInfo - new simple config format

I've created a simple (300 SLOC) API for a new configuration format (I'm not the author of it). Unfortunately, the specification is only in Polish at the moment, but you can see how it looks here. ...
2
votes
2answers
56 views

Tracking current during iteration

I have a list of posts. I need to generate it each one by one. For generation of each post, I need to know about other posts. However, I want to make the current post marked. ...
4
votes
1answer
97 views

Static blog generator

I want yet another review on my static blog generator script for improvements. ...
7
votes
2answers
137 views

Espresso Queue simulation

I was asked to do a technical test with the following specification, but my solution was rejected and I was not selected for the available position (Junior to "normal" level, with 4 days of time to ...
4
votes
1answer
168 views

Madlibs Program

I just started to learn Python, and wrote this Madlib program that works the way I intended it to, so I do not need help debugging, just some advice on tips to improve the code or make it simpler. ...
1
vote
2answers
51 views

Number of maximal PAIRS-values

I had an interview question like this: In a company there are different people. One can measure how well they suits for pair coding as follows: First, let us compute the PAIRS-value which ...
4
votes
2answers
75 views

Python List Continuation with multiple lambdas applied

I'm attempting to apply multiple filters and maps to a list and attempted to refactor into something i believe is more readable. In my code, I am reading a file to create a list of terms, then munging ...
5
votes
3answers
542 views

Caesar cipher exercise

I was doing this exercise from here. I made a solution work but can't help feel it could have been done in fewer lines. I'm quite new to python so I'm not too sure of the little shortcuts. ...
2
votes
2answers
357 views

HackerRank “Manasa and Stones” in Python

Problem Statement: Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference ...