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

learn more… | top users | synonyms

2
votes
1answer
36 views

Singleton base class

I just wrote a singleton base class for a hobby project I'm currently working on. Python is not my first language, which is why I am not sure if everything is done the pythonic way. I also used ...
4
votes
1answer
54 views

Recursive Tic-Tac-Toe Solver in Python

I'm implementing a Tic-Tac-Toe solver in Python. It contains two functions: assess to determine whether a given board position is a win for either side, and ...
10
votes
1answer
63 views

Try-except decorator for classmethods

This question is related to the Cactus Text Game Engine. For easy error handling in Cactus, we've put together this small decorator. Essentially, the decorator wraps any class method in a ...
2
votes
1answer
26 views

INTEST on Codechef in Python 3

I have written a program in Python 3 for the INTEST problem on Codechef (included in question). The program is taking a lot of time (55.76s) in Python 3. The same code takes almost 1/10 of the time ...
3
votes
2answers
54 views

Number guessing game in Python3

Is there any room for improvement? ...
3
votes
1answer
46 views

Calculate sales tax from tabular data

This is a Python 3 solution to the problem stated in Sales Tax Problem, rejected for not being up to their standards. It also seems like the same thing as the problem stated in Sales tax calculator, ...
4
votes
1answer
41 views

Monoalphabetic Substitution Cipher

In light of this months Community Challenge, I've taken a stab at building something related. Keep in mind, this isn't a submission for the challenge, just a utility to help in the later process of ...
1
vote
0answers
18 views

Handling variables in pyqt - globals vs signals vs container object vs?

While coding a medium to large scale program for the first time I tried different ways of handling a lot of variables. As I find that examples on this are quite rare on the interwebs I will try to ...
11
votes
2answers
234 views

Simple 2048 AI in Python

A few weeks ago, I wrote a Python implementation of 2048. Since then, I've been working on a simple AI to play the game for me. The code uses expectimax search to evaluate each move, and chooses the ...
11
votes
4answers
204 views

Weaving elements into a list

I have the following problem statement: Modify a given list such that one specific element is "weaved" into that list. Examples if the element is 'module': ...
6
votes
2answers
125 views

Maze BFS in Python

The program below was made for a game named CheckIO, and it works. I'm just wondering if there is any way to make the code more readable. ...
6
votes
3answers
270 views

Article start exercise

I've used encountered this exercise from a tutorial: Create a function that takes a string as a parameter and returns True if the initial word of the string ...
7
votes
2answers
155 views

Script for a Civil War game

I'm new to Python, and pretty much programming/scripting. I'm just looking for someone to critique my methods and tell me if there are more efficient ways to do things. ...
1
vote
1answer
36 views

Optimizing game camera

I'm moving some octagons around and I found a serious bottleneck: ...
7
votes
1answer
149 views

Functional programming in Python: 2048 merge functions

I've written the core functions for a basic 2048 game. I know Python isn't a functional programming language, but I like the "functional style" (easier to maintain, simple to understand, more ...
0
votes
1answer
60 views

The mood of the nation - Twitter trend

This assignment is taken from here. Introduction In this project, you will develop a geographic visualization of twitter data across the USA. You will need to use dictionaries, lists, and ...
2
votes
1answer
34 views

Denormalizing an OrderedDict to CSV

Cross post from stackoverflow, as suggested. I have an ordereddict, and I need to store it in CSV file. Input: ...
3
votes
1answer
61 views

OOP TictacToe with Tkinter

This is my implementation of a Tic Tac Toe game with Tkinter GUI. So far I've set up the game to play with another player. For an interview coming up, I am suppose to build additional feature such ...
4
votes
2answers
48 views

The Geometry of Maps - Twitter Trend

Below assignment is taken from here. Introduction In this project, you will develop a geographic visualization of twitter data across the USA. You will need to use dictionaries, lists, ...
2
votes
1answer
52 views

Move through a basic roguelike text map

I have a basic outline for the best way I can come up with to move a character through a basic text map. I want to implement this module in my simple text RPG. I know there has to be a better way to ...
5
votes
1answer
57 views

Assigning sentiment to each tweet - Twitter trend

Below assignment is taken from here. Introduction In this project, you will develop a geographic visualization of twitter data across the USA. You will need to use dictionaries, lists, ...
6
votes
1answer
59 views

Temporary file utility class in Python

I decided to write a tiny class to automatically write and delete a file given filename and content. It is intended to make testing IO less verbose. I include a small example usage. ...
1
vote
0answers
35 views

Covering Array Sorter

A covering array is a N x k array in which each element is a from a set of v symbols, and ...
11
votes
4answers
1k views

Simple text RPG in Python

I am trying to teach myself to code using Python. The following is the first real program I have written from scratch. I feel that it is messy and in need of improvement, but I am either unsure of ...
0
votes
0answers
26 views

BeautifulSoup web spider for driver links

The following spider will grab some driver links, OS version, and the name. All the info is in a table class, but some pages might be a little different in the location and Number of cells in each ...
-1
votes
1answer
42 views

Function for shuffling cards

Assignment from here Q6. Define a function shuffle that takes a list with an even number of elements (cards) and creates a new list that interleaves the elements of the first half with the ...
8
votes
1answer
91 views

Drawing circles with triangles

As pyglet has no in-built method to return a vertex list of circle, I had to build one myself. This is a critical piece of code that I will use very frequently. I need it to be of very fine ...
0
votes
1answer
55 views

Sum of all arguments ever passed to counter

Q4. Define a function make_counter that returns a counter function, which takes an immutable key and a numerical value argument and returns the sum of all ...
1
vote
2answers
35 views

Sum of all arguments ever passed to accumulator

Q2. Define a function make_accumulator that returns an accumulator function, which takes one numerical argument and returns the sum of all arguments ever ...
4
votes
3answers
119 views

Reversing the elements in the list

Q1. Define a function reverse_list that takes a list as an argument and returns None, but reverses the elements in the list ...
2
votes
2answers
75 views

Add 100 to all values in nested dictionary

I want to change all values in a multidimensional dictionary. I have written this line of code, which does what I want it to do and I am trying to find out if this is the optimal way or just some ...
3
votes
2answers
102 views

Multiple longest common subsequence (another algorithm)

Here is the algorithm: Input: a set of \$M\$ strings \$S=\{s_i\}\$ of length \$N\$ with alphabet \$\Sigma\$ Make an index of each string by chars. Maintain a position \$p=(p_i)\$ where \$p_i\$ is an ...
1
vote
2answers
64 views

Inverse mapping of a dictionary

For the below question picked from here: Write make_inverse_dict(d) that returns a new dictionary with the 'inverse' mapping. The 'inverse' mapping of a ...
5
votes
2answers
198 views

Python Trig Calculator

It's big, it's ugly, but it should work. My question is: how could I have implemented the "typeselection" function so it is less repetitive? Any tips on other improvements in coding style are welcomed ...
3
votes
1answer
65 views

Multiple longest common subsequence

Is the algorithm correct? It seems to work. ...
-1
votes
2answers
59 views

Filter a list with given predicate - python [closed]

For the following question, the function • should mutate the original list • should NOT create any new lists • should NOT return anything Function that do not create new lists ...
2
votes
2answers
292 views

Project Euler #12 runs very slowly

The problem is : The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: ...
2
votes
5answers
222 views

Shift elements left by n indices in a list

For the following question, the function • should mutate the original list • should NOT create any new lists • should NOT return anything Functions that do not create new lists ...
1
vote
2answers
121 views

Accessing argparse arguments from the class

I have the following sample code running unit tests: ...
1
vote
3answers
65 views

Mutating the list

For the following question, the function • should mutate the original list • should NOT create any new lists • should NOT return anything Functions that do not create new lists ...
2
votes
1answer
46 views

Sum of squares of each interval

Q. Write three similar functions, each of which takes as an argument a sequence of intervals and returns the sum of the square of each interval that does not contain 0. Using a for ...
10
votes
3answers
101 views

Simulating a river ecosystem

I'm currently working my way through a textbook to enhance my beginner Python skills (Goodrich, Data Structures and Algorithms in Python). The first, somewhat in-depth problem involving OOP was the ...
0
votes
2answers
78 views

PyDOS Version 3.0

This is a follow up to the questions: PyDOS shell simulation and PyDOS: Version 2.0 Introducing PyDOS 3.0! With brand new features and improved code, this will blow your mind! New Features (This ...
2
votes
1answer
27 views

General purpose input validation GUI

I decided to build a GUI that would seemlessly create user interfaces for validation functions, functions that check if a string satisfies given rules. An example ...
4
votes
1answer
42 views

Pickling cars with simple management system in Python

This is my first Python program (before that I've been just poking around with the interpreter itself). I took this opportunity to do some user input and play around with ...
15
votes
2answers
237 views

Newborn pythonic calculator

Let me start off by saying that I have several years of experience in Java, but now I need to learn Python, so I decided to make a calculator as it also is a community challenge. Please review the ...
5
votes
2answers
242 views

Math game with 'hard' and easy questions

In my competition, I was to create a game that asked at least 5 easy questions, and up to ten hard questions, summing fifteen questions. Please review my code, especially how I formatted it with the ...
0
votes
1answer
74 views

Interval multiplication - faster version

For the below given problem from this assignment: Q4. In passing, Ben also cryptically comments, "By testing the signs of the endpoints of the intervals, it is possible to break ...
0
votes
2answers
75 views
3
votes
0answers
28 views

Pyglet: scene manager

This is my brief summary of Pyglet: it's a powerful, efficient, high-tech cage. But once you're in there, once you call pyglet.app.run(), it's all over - you can't ...