Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

10
votes
2answers
91 views

Election vote-counting, result-posting chatbot

In preparation for the end of Code Review's 2015 election, I've built a simple bot to get the election votes, run OpenSTV on them, and post the result to a chatroom. I'm using this Python ...
5
votes
4answers
125 views

Guess the randomly generated number game

I've been working on this for the last few days. Any improvement ideas? (Notes are very simple, making this for school and notes have to be for complete novices to Python). ...
5
votes
2answers
246 views

Very Ugly Tkinter Calculator

I have been working for about a week on a calculator in Tkinter, and the result is a very ugly, but functional calculator. Is it possible to clean up the code, and make it more readable? ...
6
votes
1answer
56 views

Gossip algorithm in distributed systems

I have implemented the gossip algorithm in distributed systems for review. Gossip class ...
12
votes
6answers
438 views

Storytelling program: Gathers stories from certain popular story websites/formats and reads them aloud

Audiobooks make my life easier when I have idle ears and a mind free to wander, but something better for my eyes to do. This program is one of my more recent efforts to allow most of the stories ...
-1
votes
0answers
43 views

Implement min stack in O(1) [on hold]

I was asked to implement min stack in an interview and this is what I came up quickly. The get_min has to be O(1). To me I ...
4
votes
1answer
77 views

Order a list of tuples or a NumPy array in a specific format

I have a list of tuples or a NumPy array (it can be either of them as the variable comes as a list and will end up being a NumPy array) and I want to order them in a specific way (that I am not able ...
-1
votes
1answer
23 views

Triangled printing

This code prints numbers in a triangled way, such as: 1 12 123 12 1 This is the code: ...
3
votes
3answers
500 views

Fibonacci sum with memoization

Problem: Using the recursion approach, find a Fibonacci sum without repetition of computation. ...
5
votes
3answers
281 views

Inverse cascade challenge - Recursion

Print the following pattern, when you invoke inverse_cascade(1234) 1 12 123 1234 123 12 1 Solution: ...
2
votes
0answers
27 views

Passing around and using Python dicts [on hold]

I have an Excel file - a profit spreadsheet - which has one tab per product range. The tabs are defined and named, but apart from that, the file contains no data (yet). I wish to use ...
7
votes
1answer
145 views

GCD using Euclid algorithm

Below is the problem taken from here. Question 10: GCD* The greatest common divisor of two positive integers a and b is the largest integer which evenly divides both numbers (with no ...
2
votes
1answer
90 views

Reading, writing and filtering a CSV file

I have a CSV with 5+ million rows and I want to filter it: ...
5
votes
2answers
76 views

Text justification

This is the Text Justification challenge at LeetCode: Given an array of words and a length \$L\$, format the text such that each line has exactly \$L\$ characters and is fully (left and right) ...
3
votes
1answer
21 views

Bayesian monophyly testing from MrBayes and BEAST posterior tree samples

I wrote a script that tests monophyly by computing Bayes Factor on a sample of trees from Bayesian MCMC analysis from MrBayes and BEAST posterior tree sample files. This is the natural way I write ...
5
votes
4answers
152 views

Register/Login and authentication through terminal

This is a registration and login program I made in Python that runs through the terminal. I am new to programming so I didn't have any actual use for this, I simply made it for practice. Please give ...
3
votes
1answer
40 views

Gmail Data Analysis

I am using Imaplib to fetch data from Gmail and get the number of emails each day. I am going to login using Imaplib twice for fetching emails for the inbox well as for the outbox (sent mail). Is it ...
-1
votes
0answers
17 views

Faulty end of game [on hold]

Making another simple game, and this time my problem is the final number. The basis of the game is two players choose a number between 10-50, and have to take it in turns deducting either 1,2, or 3 to ...
2
votes
1answer
39 views

LRU cache design using dict and doubly linked list

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the ...
3
votes
1answer
35 views

Find allele frequencies at each site for each iteration for each population from FASTA file

The script takes a FASTA format file in input and outputs the frequencies of each amino acid (A, C, ...
6
votes
1answer
45 views

Enumerating Chess Piece Moves

There was a question asked recently here that went through enumerating moves for a chess piece. I was going to write an answer for this question, but while I was bashing out some code to throw into an ...
3
votes
3answers
26 views

Determining which octant has a specific point

I am interested in octants in plane geometry, which basically involves dividing a plane into 8 equal parts according to a certain point. Octants are particularly useful while implementing the ...
1
vote
1answer
102 views

Insect combinatorics challenge

Below is the problem taken from Berkeley's Cs61A page here Question 9: Insect Combinatorics* Consider an insect in an M by N grid. The insect starts at the bottom left corner, (0, 0), and ...
0
votes
4answers
578 views

Percentage of digits in n that are even

Question 7 from Lab 3 of Berkeley's CS61A course says: The following examples of recursive functions show some examples of common recursion mistakes. Fix them so that they work as intended. [...] ...
5
votes
0answers
89 views

Average movie rankings

Given a list of tuples of the form, (a, b, c), is there a more direct or optimized for calculating the average of all the c's ...
6
votes
0answers
46 views

TLS encryption with a self-signed PKI and Python’s asyncio module [on hold]

I want to enable TLS encryption with a custom / self-signed PKI for a self-contained distributed system built with Python 3’s asyncio. I’ve read Python’s ssl docs as well as several tutorials: ...
1
vote
0answers
31 views

Implementation of a simple problem to check contests eligible for next round [on hold]

I am trying to solve a simple problem but it judge on codeforces is giving me errors seems like I am missing an edge case most likely. Below is the problem and the source code I have written to solve ...
0
votes
3answers
40 views

Python Decorator - inspecting function argument values

Some of my functions use a "fail_silently" flag. It is used in the following way: ...
4
votes
2answers
42 views

Reading and merging multiple data files

I've recently started teaching myself Python but have no prior programming experience or formal training. I've successfully created a program that outputs what I wanted it to output, but I'm looking ...
4
votes
2answers
75 views

Project Euler - Problem 54: testing poker hands

This was a very fun and thought provoking problem, and I'm quite proud of the way I was able to pull it off. I broke it down into 2 parts, testing and comparing. Testing each group of cards for ...
14
votes
3answers
1k views

Very simple Python preprocesser that allows “until” and “unless” statements

I've implemented the beginnings of a Python preprocesser I plan to implement sometime in the future, and the below code is my simple prototype. At the moment, it only converts ...
8
votes
1answer
128 views

Fractal rendering fun time

I wrote up a script a while back to let me play around with fractals. The idea was to have direct access to the script that creates the fractal. None of that close, edit, then run hassle; just edit ...
-4
votes
2answers
46 views
5
votes
5answers
152 views

Enumeration of random trees

I'm interested in recursive generation of trees in Python. For my eventual application, it's important that the trees be represented as a list of nodes (rather than say a dictionary, or an edge list, ...
6
votes
1answer
58 views

List querying capabilities in Python 3.x

Either out of boredom, or my odd fascination with LINQ and SQL, this, thing, was created. Essentially, it provides list querying capabilities. At the moment, you can only query lists based on ...
0
votes
0answers
29 views

@contextmanager: do some clean-up, then reraise an exception [closed]

Imagine I'm writing a simple context manager using the @contextmanager decorator. If an exception gets raised I need to a little bit of clean-up before the program ...
1
vote
0answers
46 views

Fast row-wise, parallel calculations on large, sparse matrix

I have a big (50k*150k) matrix with co-occurrences of nouns (rows) and adjectives (columns). As most nouns don't co-occurr with most adjectives, this matrix is very sparse, >99.9%, so I'm using the ...
3
votes
1answer
37 views

Transaction.atomic with continuations

I have a view that looks like this: ...
3
votes
4answers
79 views

Are the words isomorph?

Are the words isomorphs? (Code-Golf) This is my non-golfed, readable and linear (quasi-linear?) in complexity take of the above problem. For completeness I include the description: Two words are ...
3
votes
2answers
61 views

Add two 4-D arrays in Python

I have two arrays, each with shape (1, 51, 150, 207) I need to add them such that: ...
3
votes
1answer
51 views

Batch Gradient Descent running too slowly

Following Data Science from Scratch by Joel Grus, I wrote a simple batch gradient descent solver in Python 2.7. I know this isn't the most efficient way to solve this problem, but this code should be ...
4
votes
1answer
124 views

Comparing FFTs to deduplicate IVR recordings

I've got a Python script that traverses two file trees, checking all .wav files for duplication. I'm still an undergrad, and have never worked with audio before. I'm not entirely sure this is going ...
2
votes
2answers
72 views

Program that reads 4 files and outputs contents of it into another file after formatting it

The below Python 3 program scans 4 files a.txt, b.txt, c.txt, ...
5
votes
2answers
69 views

Private client-server chat

I try to create a private chat with Python but I don't know best practice. It's only for study purpose, I'd like understand the logic behind a simple private chat with socket and the best mode to ...
3
votes
2answers
198 views

Unique letter counter for string in Python

I'm trying to create a program that creates a record of how many times letters appear in a given string (ignoring blank spaces) using recursion. ...
3
votes
1answer
42 views

Downloading 2 tables from db, does calculation and uploads resulting table

I have written this script that downloads two tables from the db, preforms an intersection on them and adds 2 new columns to the resulting table, and uploads the resulting table to the db. It's a bit ...
6
votes
1answer
65 views

Topological sort

The algorithm works in steps: Produce the graph in the form of an adjacency list e.g. this graph 0 - - 2 \ 1 -- 3 produces this adjacency list ...
2
votes
2answers
39 views

Converting a 1D Array of Strings to a 2D Array in Python

I was solving this question on a site that gives you a 1d array called grid ...
3
votes
1answer
52 views

Python Knapsack problem: greedy

A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for ...