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

learn more… | top users | synonyms

-2
votes
0answers
12 views

How do I complete this Python Tennis Kata? [on hold]

I'm trying to write the Tennis kata in python. I've written the code for a standard game, but somehow cannot figure out how to write the Deuce part. Could someone give me an algorithm or help me ...
3
votes
1answer
23 views

Decorator that supplies arguments to functions

I have assignment to generate argument based decorator I wrote like this. ...
0
votes
1answer
40 views

Exponentiation using while loop in Python

I could not think of any better way to raise to power, except this, but how do I refactor it? I should only use while loop, not for loop, not x**y. I shall not use pow(x,y) ...
1
vote
0answers
15 views

PEG parser generator

I wrote a Python PEG parser generator that takes a grammar as a string, and returns a parser. The parser can parse its own syntax, and is feature complete with the original PEG paper, with some ...
3
votes
2answers
26 views

Combining values corresponding to the same key

What the following code does is: The key field is column0 (where sometimes there could be single key, and sometimes keys separated by comma). The rest of the columns are also either single or comma ...
0
votes
0answers
17 views

Small implementation of an Observer in Python

Good Evening, I wanted to start with the Entity Component System but for that I have realized I should have know some basic patterns. So here is my implementation of an Observer. Later on I also ...
3
votes
1answer
24 views

Calculating chmod based on user input [on hold]

This program asks the user for input three times, and based on that input, calculates the chmod. I have included comments with questions and clarifications in the code. I would like to have these ...
0
votes
1answer
21 views

Python - Print the average of a list which is a value in a dictionary [on hold]

Imagine I have a dictionary like this: class1 = { Max: [9, 7, 10], Jhon: [3,2,1] } The values for each name is stored as a list object. I have used this code ...
0
votes
1answer
38 views

Get time slots based on multiple workshops

I have a list of Workshops, each having open days (Monday, Tuesday etc.) and open time and close time (which will be same for each day). Now, Based on the current time, I need to find out next 7 days ...
4
votes
3answers
103 views

Hungry ant AI: any food here?

I'm working on a little AI to simulate ants (very basic). The full code can be found on Github. This function (in Ants.py) takes a list of Tuples containing ...
2
votes
2answers
43 views

Find the median value of a list

I am taking an online training course on Python, and am at the following question: Write a function called median that takes a list as an input and returns the median value of the list. For ...
1
vote
1answer
35 views

Printing chessboard with *(asterisk) and .(dot)

I have written a program in which user enters total number of conditions (cases) and then that many number of inputs to print chessboard. For example: ...
2
votes
1answer
44 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 ...
1
vote
0answers
15 views

Singleton method for Redis connection in Python

Here's my class for providing a singleton instance of a Redis connection. What do you think? ...
0
votes
1answer
54 views

Project Euler problem #11 - Largest product in a grid

I have recently solved the following Project Euler problem: In the 20×20 grid below, four numbers along a diagonal line have been marked in red [here bold]. ...
1
vote
0answers
31 views

Simple YAML-based config file parser

I have written a simple yaml based config parser in Python. The idea is that it will get passed around in other scripts after being initialized with a config file within a main function. I am ...
0
votes
0answers
33 views

Membership information [duplicate]

A file paintingJobs.txt shows Estimate Number, Estimate Date, CustomerID, Final total (in pounds), Status(E for Estimate, A for Accepted job, N for Not accepted), and Amount Paid (in pounds). ...
0
votes
1answer
58 views

Tic Tac Toe (Player vs Computer)

Hi I am looking on how I can improve my writing style and/or how to simplify how I write my code. Thanks in advance! ...
3
votes
0answers
21 views

Rolling OLS algorithm in a dataframe

I want to be able to find a solution to run the following code in a much faster fashion (ideally something like dataframe.apply(func) which has the fastest speed, ...
-5
votes
0answers
22 views

removing an object using lists, stack and queue [on hold]

Trying to remove all objects with the colour orange from my program which are in the list ,stack and queue. Currently having difficulty on how to progress from my code and just need to get an idea of ...
2
votes
1answer
36 views

Crawling through a YouTube channel via the YouTube API

This code uses the YouTube API for crawling through a YouTube channel, parsing responses and syncing the channel videos with a local directory. Can this be optimised or improved? ...
1
vote
1answer
18 views

Python exception handling class - Getting as much details printed

I'm trying to write a Exception Handling class in Python so that I can re-use. If you have any ideas on how I can improve this to output more detailed information I would appreciate it: ...
4
votes
1answer
33 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
29 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
29 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 ...
-1
votes
1answer
36 views

Finding Sylvester sequence code

I've written this code to calculate the Sylvester sequence, which is defined as $$s_n = s_{n-1}(s_{n-1}-1)+1$$ where \$s_0=2\$. ...
-3
votes
0answers
32 views

Code for Sylvester sequence [on hold]

I need to code the Sylvester sequence in Python. The formula for the sequence is defined as $$s_n = 1 + \prod_{i=0}^{n-1}s_i$$ Where \$s_0 = 2\$. However, I am having too much trouble writing this ...
0
votes
2answers
55 views

Currency converter in Python 2.7

I'm a beginner and it is my first project in Python 2.7. My goal is writing a script that I can run with two or three arguments. If run with two arguments like ...
6
votes
1answer
109 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 ...
-1
votes
1answer
52 views

Displaying membership information

The code is about displaying membership information of all clients from a database. This is for homework and I'm just curious if more can be done to improve this. Feel free to alter it, but please ...
0
votes
0answers
33 views

Is this implementation of memcmp() correct in python [closed]

I was trying to implement the memcmp(). I wanted to know whether I have accounted for all the edge cases. Can it be really used(not considering performance constriants) as a drop-in replacement for ...
1
vote
1answer
35 views

TicTacToe Telnet server in Python

The code below works. The timings are as close as I can get to the system not packing out. Basically telnet to a server to play tic-tac-toe. Automated it. Bottom left is 1, middle left is 2, middle ...
5
votes
1answer
49 views

Python Octree Implementation

I'm working with 3D point clouds stored in Numpy arrays. I'd succesfully used the scipy's KDTree implementation for task like k-neighbors search and outlier filtering. However I wanted to try the ...
4
votes
1answer
66 views

Sieve of Eratosthenes solution for CodeEval

The code below takes integer n as input, and delivers a list of all primes up to integer n using the Sieve of Eratosthenes. My question is, could you please help me optimize this code? Is it ...
0
votes
0answers
38 views

Coins changing with recursion [closed]

So I occurred a with a coins changing problem. I have a fully functional source code, but I need another one or maybe there is possibility to rewrite it and make easier to understand. I want to find ...
-1
votes
0answers
15 views

How to parse command line arguments from python nosetests plugin to testcase [closed]

I am writing a simple nosetests plugin. The aim is to parse the arguments from command line, then this parsed value could be used in the testcase. Some previous posts advised to use global variable, ...
2
votes
1answer
50 views

Clustering similar tweets in a corpus

I am attempting to write a statistical program using an LDA model I've trained/created using Gensim. I am very new to Python and am a student level programmer. This current program is working and ...
-2
votes
0answers
41 views

Count decimal places of pi number

My program asks how many decimal places of pi number do want to see. I would like to ask for your review about my code. I have also two questions: Why I had to add 1 (getcontext().prec = places+1) ...
4
votes
2answers
71 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: ...
2
votes
2answers
52 views

Designing a sorting algorithm from scratch

I'm taking a Python course and the current assignment is to create an algorithm that sorts numbers in ascending order (without using built-in sorting functions). I've had no programming experience ...
1
vote
2answers
41 views

Permute and count between nested dictionaries

Goal: Permute inner values between two dictionaries with matching outer key, Save permuatations in counter, Move to next outer key, update counter with new permutations. Problem: Many lookups on ...
-5
votes
0answers
20 views
3
votes
2answers
86 views

Displaying member information from a CSV file

The code is about displaying membership information of all clients from database. I was just wondering what I could do to improve/change it. ...
2
votes
0answers
20 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 ...
0
votes
1answer
69 views

Context manager for SMTP connections

My code right now look like this ...
3
votes
1answer
112 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? ...
0
votes
2answers
62 views

Summing all keys in the leaves of a tree

My program takes 35 sec to run example 2. How can I make my program faster? ...
6
votes
2answers
55 views

Creating a family hierarchy

Requirement: For the input list of tuples to create single line output showing father of the family|spouse|child1,child2.... Input: ...
4
votes
0answers
27 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 ...