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)

3
votes
2answers
26 views

Pig Latin Translator in Python

I am a relatively new Python programmer and made a simple Pig Latin to English translator and vice versa. I would just like it if someone reviewed my code and see if anything can be done to make it ...
4
votes
3answers
229 views

Finding factorials

How can this script be optimized? ...
2
votes
1answer
19 views

Memory game using python and pygame

I am a beginner in python and pygame. I wrote a memory game using python 3 and pygame. I think there are lot of things I could have done better.So I am looking for some advice on how to improve the ...
2
votes
1answer
27 views

1-dimensional and 2-dimensional Peak Finding Algorithm

I have the following code for a peak finding algorithm in Python 3.4.3. A peak is an element that is not smaller than its neighbors. ...
8
votes
2answers
93 views

Finding a string whose MD5 starts like the digits of π

I tried to make a program to find a string whose MD5-hash starts like the digits of pi, where dot is omitted. Is there a faster way to do it than this: ...
-1
votes
0answers
42 views
3
votes
1answer
35 views

Maximize points won by flipping coins

So, there is this king-of-the-hill challenge going on at PPCG SE to which I submitted my participation. I won't change it further in terms of behaviour, so I wanted to know what you think of the code. ...
1
vote
1answer
37 views

Longest Palindromic Substring

I wrote the following code for this problem. The problem is to find the longest palindromic substring. I think it is correct and is working correctly for all the test cases I entered myself. Now, the ...
2
votes
2answers
40 views

Program to edit an address book stored as a JSON file

I was told to come here from Stack Overflow. I'm trying my hand at an address book and the goal is for it to have a bit more of error prevention, for instance for the key "phone" to have 10 digits, ...
1
vote
1answer
23 views

Python list “commander” (modify a list with user commands)

I made a program that can modify a list using commands that the user enters. The commands that are supported are (used from actual program): ...
7
votes
4answers
1k views

Simple python calculator

I'm very new to Python, and so I'm trying to learn it by doing simple programs, like a calculator. But I don't know if this is the "Pythonic" way to do it, or if I am making beginner errors. So ...
3
votes
1answer
30 views
-6
votes
0answers
16 views

is this code right? [closed]

class Node: def init(self,value): self.element=value self.next=None class Queue: def init(self): self.length=0 self.head=None self.tail=None ...
2
votes
1answer
48 views

Performance optimization when switching from nested to flat representation (genetic algorithm)

The code below is the core of a Genetic Algorithm (NSGA-II to be precise, without crowding-distance calculation), but I've taken out all the GA-specific parts and made a generic example. I think I've ...
4
votes
1answer
39 views

Saves Scores of an Arithmetic Quiz

This code is part of a larger code that generates an Arithmetic Quiz, although the code I have show below just saves the score that the user got on the test and their name. When saving the code it ...
0
votes
3answers
37 views

Making my code look neater [duplicate]

Is there anyway I could tidy this code and make it look better and more appealing? ...
3
votes
1answer
34 views

Method injection into TestClass local namespace for automatic generation of Python unittest “test_xxx” methods

I am writing a series of unit tests in Python 3.5 unittest, which run the exact same test methods on different datasets. The purpose is to validate proper behavior ...
7
votes
1answer
118 views

Chopsticks game in Python

As a beginning project, I decided to code something that plays the game Chopsticks in Python 3. I'm using the Minimax algorithm, and exploring the tree using simple recursion. One of the main problems ...
4
votes
2answers
76 views

Python common file operations generalization

Functions with common and simple file operations have started to repeat in my code. Many like this one, but with subtle differences for example: ...
1
vote
2answers
29 views

Project Euler Problem 10

Project Euler problem 10 is to find the sum of all primes less than 2 million. I have written a program that does this, and it works, but it takes an excruciatingly long amount of time. What I'm ...
2
votes
0answers
23 views

PySpark Dataframes program to process huge amounts of server data from a parquet file

I'm new to spark and dataframes and I'm looking for feedback on what bad or inefficient processes might be in my code so I can improve and learn. My program reads in a parquet file that contains ...
3
votes
1answer
114 views

Making the Levenshtein distance code cleaner

I was writing an implementation of Levenshtein distance in Python and I found my code really ugly. Have you any idea how to make it more elegant? ...
4
votes
0answers
28 views

Computing the in-degree of a tweet graph

This was my entry for a recent coding challenge for computing the in-degree of a tweet graph (the competition is over). The requirement was to compute the in-degree of a graph made from unique hash ...
3
votes
2answers
72 views

First time writing test case

I have a list of input, a greedy method and a dynamic programming method. I wrote a unittest script to test my two methods with input list but I don't know if I'm writing it right: ...
2
votes
2answers
12 views

Shortest regex search and sum for integers

Given a text file including different text and integer numbers (text.txt), what's the shortest way of getting the sum of all the numbers out if it? I have: ...
18
votes
4answers
2k views

Battleships game in Python

The idea is, you enter an amount of ships, for example 10. It will then place 10 ships on a 10x10 grid (0-9). You may enter a coordinate, and it will tell you if it is a hit or a miss. A simplified ...
1
vote
1answer
13 views

Python 3 Packages, Modules, and Classes - is this approach any good? [closed]

After reading a decent amount in this area, I've come up with the following for myself. __init__.py has imports of all submodules which are intended for outside ...
4
votes
2answers
76 views

Reversi (Othello) in Python

I'm a beginner-intermediate programmer who's mostly used Java. I taught myself Python and made this engine for playing Reversi. Tips on Pythonic ways to accomplish tasks and/or general advice ...
1
vote
1answer
43 views

Python CSV reader

I have a function that pulls data from a file or string literal in my case and returns them in either a list or a dict. My ...
1
vote
2answers
21 views

Inputting multiple strings and finding their length

I need to find the length of elements within a string and return it to the user. What is the best way of simplifying this code to make the amount of string lengths equate to user input? Also, how can ...
3
votes
1answer
35 views
1
vote
1answer
33 views

Store and output hard-coded relationships among hosts

The following code has begun to smell, but I have not yet decided with what to replace it, other than, obviously, a database. I made a very unsatisfactory workaround for my attempt to make ...
2
votes
4answers
526 views

regex to extract version info

I have written a small Python function to extract version info from a string. Input is of format: v{Major}.{Minor}[b{beta-num}] Eg: v1.1, v1.10b100, v1.100b01 Goal is to extract Major, Minor and ...
3
votes
1answer
84 views

Dijkstra's algorithm: traditional and bidirectional in Python

I have translated Dijkstra's algorithms (uni- and bidirectional variants) from Java to Python, eventually coming up with this: Dijkstra.py ...
1
vote
0answers
60 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 ...
0
votes
0answers
33 views

Representation of an artificial neuron

I didn't used 2 parameters in the neuron for the input (like neuron(x1, x2)) because, everywhere I was reading about input ...
2
votes
1answer
33 views

Working with a puzzle class to determine stuff

I was given the task of making a grid peg solitaire puzzle. Here are the programs, the basic puzzle file, and the actual grid solitaire puzzle: The puzzle software ...
1
vote
0answers
48 views

Cyther: The Cross Platform Cython/Python Compiler (Take 2)

I recently posted an earlier version of this code on Code Review, and now with the given suggestions and many other improvements, I am back. I included the description of exactly what Cyther is ...
2
votes
1answer
61 views

RPi script to periodically collect data from Arduino through serial port

I'm not used to Python. The script opens serial communications with an Arduino unit and send commands to and receives information from the Arduino. It is intended to run indefinitely until the system ...
4
votes
2answers
107 views

Basic Python Tic-Tac-Toe Game

I have just decided to get into programming as a hobby (and possibly a job in the distant future). After learning the basics of Python, I made Tic-Tac-Toe to apply what I've learned. I would ...
1
vote
2answers
60 views

Find a specific file, or find all executable files within the system path

I wrote a function to find a specific file, or all the executable files with a given name and accessing flag, and I want to make ...
6
votes
1answer
646 views

Breadth-first search on a tree in Python

The following code performs breadth first search on a mockup tree ...
1
vote
1answer
53 views

Remove non-printable characters from string in Python 3

My aim is to print bytes string lines in Python 3, but truncate each line to a maximum width so that it fits the current terminal window. My first attempt was only ...
3
votes
1answer
70 views

Basic sorting in Python

Previously asked here. I would like to get my code for implementation of simple sorting algorithms in idiomatic python code reviewed. I am looking for feedback on python idioms used, better ways of ...
2
votes
1answer
73 views

Implementing basic sorting in Python

I would like to get my code for implementation of simple sorting algorithms in idiomatic python code reviewed. I am looking for feedback on python idioms used, better ways of doing the same thing. I ...
1
vote
0answers
25 views

Unit tests for a Redshift wrapper class

I'm somewhat new to TDD and unit testing, but I've written a suite of unit tests to check my functionality. The basic classes automate simple load and unload operations from s3 and redshift, and ...
1
vote
2answers
69 views

GUI Caesar Cipher with model-view-controller

I created a Caesar Cipher Program in Tkinter, to help me learn the Model-View-Controller concepts and Tkinter in general. The code works, but it is a mess, and I want some help on cleaning it up, ...
5
votes
2answers
103 views

Python simple battleship game

I'm relatively new to Python, I decided to make a simple battleship game. Is there anything I should do to make it shorter, or in practice, "better"? ...
6
votes
1answer
44 views

Aligning out-of-sync subtitles

This is my 2nd program I wrote on my own, a pretty simple program consisting of two functions (those functions are not combined in any way yet though). The first function moves the display times of ...