Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.
2
votes
1answer
23 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 ...
4
votes
1answer
113 views
Python prettyXML and prettyHTML functions
After much searching around the web, I couldn't find a single module which did a decent prettyXML or prettyHTML. Because:
...
4
votes
1answer
62 views
Finding the minimum number of required deletions to have a non-repeating string
I wrote code for the following problem:
Given a string, print out the number of deletions required so that the adjacent alphabets are distinct.
Please suggest different methods by which I can ...
1
vote
2answers
55 views
Book pages algorithm dealing with digit sum and squares [on hold]
I would like some help condensing this code to make it more efficient. Could someone also help me output the number of pages she reads instead of the page number she is on...
...
4
votes
2answers
47 views
Faster way to perform function calculation in Python?
I'm interested in whether there is a way to further improve a "fast" version of a function used in a homework assignment I received recently (I've already submitted the completed work).
...
8
votes
1answer
65 views
Python-based Git pre-commit hook to manage multiple users/Git identities
A couple of months ago I posted a bash script to manage multiple Git identities as a solution on Stack Overflow but soon found the hook isn't flexible enough.
Thus I decided to rewrite the hook in ...
0
votes
0answers
24 views
Simple k-means implemention using Python3 and Pandas
Is there anything I can improve? The distance function is Pearson correlation.
...
4
votes
3answers
244 views
Truth Table Calculator
In of my software engineering classes, I had to write a truth table calculator in the language of my choice. This is what I came up with, and I would like to know what I should do better next time:
...
1
vote
0answers
24 views
PyQt5 GUI Application
I'd just like this PyQt5 code reviewed. I'm relatively new to classes and GUI programming, and wanted to make sure I wasn't doing anything too bad. If absolutely necessary, I can give you the other ...
3
votes
2answers
110 views
Validate Move Pattern Chess
A while ago, I was working on a chess project with a couple other people. In the end, I wrote all but a couple of the lines of code, including these:
...
3
votes
3answers
37 views
CR2 raw image file parser in Python 3
I haven't used Python in a number of years, but recently started working on a project called Photoshell which is written in Python 3.
As I attempted to learn the "Pythonic way", I wrote a parser for ...
5
votes
1answer
101 views
Object-oriented Conway's Game of Life
I have Conway's Game of Life working now and was hoping for direction on:
Unclear code - where would comments make it clearer?
Poor design choices - I already know of one in the ...
1
vote
1answer
28 views
Autoclicker Tkinter Program
I made my first program that I might actually use and I was wondering if anyone had some tips on how I could improve it.
My code is an auto-clicker that uses Python3 ctypes for the clicking and ...
6
votes
2answers
89 views
1-player Battleship game - follow-up
This question is a follow-up question of this one.
I've learnt a bit more Python since then. I recently came back to making battleships again, and I think I did better.
These are the changes I've ...
5
votes
1answer
45 views
Print the list of winter bash 2014 hats as a list of checkboxes in GFM format
In Winter Bash 2014,
since there is no easy way to see the hats I'm missing per site,
I decided to use Gists for that.
A perhaps not so well-known feature of GitHub Flavered Markdown (GFM) format ...
2
votes
2answers
51 views
Function caller (to multiple receivers) interface
This class is designed to call a similar function of multiple objects of multiple classes using a single interface (it is not for calling functions that return a value).
A potential usage will be ...
2
votes
2answers
109 views
List comprehension: avoid duplicate function call
to_convert_files = [FileEnc(filename, getEncoding(filename)) for
filename in filenames if getEncoding(filename) != None]
The problem here is ...
5
votes
2answers
26 views
Activity-based permission checking
I threw together this Python function to check if a User has a certain Permission.
First of all, Permissions have this kind of format: ...
4
votes
2answers
42 views
Mailinator automatic checker for new e-mails
I'm making a little script to run on the background and notify me when I received a new email in a mailinator inbox. I want to eventually daemonise it, but for now it just runs like a regular script.
...
6
votes
2answers
53 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 a lot of time.
The main problem is just to return an array containing all \$x\$ satisfying both ...
4
votes
4answers
78 views
Calculate all cyclic subgroups of a group under multiplication of modulo n (group theory)
The task was to calculate all cyclic subgroups of a group \$ \textbf{Z} / n \textbf{Z} \$ under multiplication of modulo \$ \text{n} \$ and returning them as a list of lists. The first level has all ...
10
votes
2answers
393 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
123 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 ...
5
votes
1answer
39 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
79 views
11
votes
2answers
276 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
69 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
214 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 ...
4
votes
1answer
58 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
39 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
51 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
355 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
812 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
118 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
51 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
127 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
160 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
78 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
54 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
39 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
124 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
72 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
116 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
94 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
82 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 ...