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

learn more… | top users | synonyms

3
votes
0answers
18 views

Generating matrix/image kernel from List

First of all, if this question belongs to Stackoverflow. Mention about it. I have another question from same program where is full code, but this question focus only single process/function of that ...
2
votes
0answers
9 views

Python simulacrum of windows copy window

I wrote a program to copy files with an progress bar that looks similar to Windows built in function. The copy function is run in a separate thread and the tkinter GUI is run in the main thread. This ...
2
votes
0answers
32 views

Monte Carlo simulation to price an Option in Python

In what ways can I make this code more efficient? I haven't put in comments and descriptions yet. I need to do that. Ideally, I'd like to make the S, v, r, and K user entered as I did with T. I'm ...
1
vote
2answers
18 views

Largest substring which starts and ends with some substring

This code is meant to find the length of the largest substring within a string that starts and ends with a given non-empty substring. Here are some examples: ...
1
vote
1answer
26 views

Finding all factors of n efficiently

This function generates all factors of an input n. It begins at the square root of n, and checks numbers down to zero. When a factor x is found, then another factor must be n divided by x. Also, if ...
1
vote
0answers
29 views

Word comparison in Python

I'm developing a Python script which looks up over a huge-prelexicographically sorted list of different words (such as 33.000) and the goal is to remove those words which have less than two letter ...
4
votes
1answer
37 views

Find a famous writer in a random string

I'm doing a CodeEval challenge, where the object is to find a famous writers name and a year, inside of a random given string. You have a set of rows with names of famous writers encoded inside. ...
2
votes
2answers
123 views

Coordinates list parser/compressor

I have a little function that parse a nested list of coordinates into a flat list of compressed coordinates. By compressed coordinated, I mean that only the delta (distance) between each coordinates ...
4
votes
2answers
69 views

Justify Text using LaTeX method

I wrote a bit of code that takes a file, justifies the text and writes to another file. It uses a DP approach to minimise a badness metric, which is the amount of under or overshoot of the line ...
3
votes
1answer
52 views

Find Row Pairs that are never both 1

Given sample_size many arrays of length dim. For each index from 1 to dim, i want to give a list of indices, where no sample ...
3
votes
1answer
38 views

Multiplication Exercise Generator

I'm new to programming in Python, and I am trying to create a multiplication exercise generator. I've got the following code for the solution, but I'm wondering if there is any more elegant solutions ...
3
votes
2answers
65 views

Converting an integer to Greek and Roman numerals

Yesterday I posted a question about converting an integer to it's Roman Numeral equivalent. Apparently you guys liked it and gave me some good advice, so I decided to take all your advice, and go a ...
0
votes
0answers
40 views

Match the maximum consective count of `)` followed by a keyword

I am applying a regular expression to match and keyword that is followed by maximum number of closing parenthesis. Code is done in python using ...
8
votes
2answers
1k views

Rock, Paper, Scissors - Python game

This is my attempt at making a 'rock, paper, scissors' game in python. The game takes the user's input and the computer's random selection and calculates who has won. All feedback appreciated. ...
5
votes
1answer
58 views

Civil status database with Django

I'm beginning with Django and I have a Civil Status project. I created my first models.py in order to get a Form, but I had some advices in order to normalize my database. I made this process and I ...
4
votes
0answers
33 views

Elegant way to alter datasets with explicit filters

I would like to write a small helper to filter datasets. Each dataset is a dictionary and some filters I want to apply are common to all the datasets. That my needs, I wrote this following pattern: <...
2
votes
1answer
29 views

Get a path between graph nodes using breadth-first search

This code is meant to implement a Graph class which has a method that returns a path between 2 nodes using breadth-first search. I'm doing this to improve my style ...
5
votes
1answer
54 views

Trie implementation in Python

I have created a trie in Python and am looking for feedback. Specifically, I am looking for feedback on: If my code is 'pythonic' If my logic is proper when inserting and retrieving from the trie I ...
6
votes
0answers
79 views
+50

Decoding grayscale PNG and performing Prewitt operator for edge detection

I'm a hobbyist programmer. What I try to do here is to read 8-bit grayscale PNG file. Then unfilter it. (That caused a headache). And after that perform Prewitt operator for "edge detection". I know ...
4
votes
1answer
41 views

Decide if number is Armstrong number

I just recently started reading the python.org documents and it looked like a really interesting language. Now, since Visual Studio 2017 supports Python, I decided to finally actually start learning ...
1
vote
0answers
23 views

Simple REST-API using Python with falcon

I have a basic example of a REST API that I've done to control LEDs. I've read Dr. Dobbs article about REST and how to do it but I feel that my example doesn't look professional for some reason. ...
5
votes
2answers
303 views

Convert an integer to its Roman numeral equivalent

I got sent a challenge from a friend; You are given a file that contains numbers, one number per line. Convert the numbers from the file into roman numerals. ...
0
votes
0answers
17 views

Parsing a text file with a custom hierachial data structure using Python [on hold]

I have a text file with a certain data structure that looks like this. I have intended it to make the structure clearer, but in reality they are all aligned, and there are no bullet points. Ellipses ...
0
votes
2answers
41 views

Concatenate function arguments with “AND” string if they're not None.

Basically, if the function parameter is None, I ignore it, else I concatenate all arguments like arg1:arg1_value AND arg2:arg2_value AND arg4:arg4_value considering ...
3
votes
2answers
50 views

Get subsets of a set given as a list

This code is meant to create a list of subsets of a given set which is represented as a list. I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures ...
1
vote
1answer
54 views

Computing Gini Impurity (for node split in Random Forest/ Random Ferns Classification algorithm)

I am implementing the Random Ferns Algorithm for Classification. For simplicity, lets imagine a single decision tree with only a single node. As input we have a feature and the label of each dataset. ...
-2
votes
0answers
12 views

embedding matplotlib on c++ [on hold]

I am trying to embeed matplotlib on my c++ code, I am following this https://github.com/lava/matplotlib-cpp but when I run the code: ...
3
votes
0answers
55 views

Python AVL Tree

While learning python, I decided to implement some data structures, this time AVL tree. I think the logic is correct, is there a way to make it more clearer and any ideas to add more tests? ...
7
votes
2answers
76 views

Recursive higher-order function

I have implemented a through function for myself in a project. Since I am still quite new in python and want to learn it correctly, I would be happy about any ...
2
votes
1answer
33 views

Threaded and asyncio API library

In Python I am trying to create an API for a connected device. I want to be available for both threaded (using request) and async applications (using aiohttp). What I've come up with is wrapping the ...
1
vote
2answers
48 views

Find median of list of integers

This code is meant to find the median of a list of integers. The list is assumed to be of odd length. This is based of this HackerRank question. I'm doing this to improve my style and to improve my ...
1
vote
1answer
28 views

Return a path between graph nodes using depth-first search redo

I previously attempted to implement a Graph class which has a method that returns a path between 2 nodes using depth-first search. This is my latest attempt at this ...
4
votes
1answer
67 views
1
vote
1answer
28 views

Return path between graph nodes using depth-first search

This code is meant to implement a Graph class which has a method that returns a path between 2 nodes using depth-first search. I'm doing this to improve my style ...
1
vote
2answers
97 views

A simple pocket calculator

I was searching the internet for some Python exercises, and I've found a lab assignment from University of Toronto. Here's the major of it: Question 1. Welcome Message In the if ...
5
votes
2answers
276 views

Reduce as many adjacent chars as possible in string

This code is meant to reduce a given string as much as possible by deleting adjacent characters. Here are some examples: ...
-2
votes
0answers
16 views

Difference between Python and C++ code for Finding the minimum lcm of list of numbers [closed]

I am trying to solve this problem: https://www.codechef.com/problems/ALEXTASK and I have two solutions for this. One in C++ ...
2
votes
1answer
39 views

Compute the probabilities of getting each of the possible sums when throwing 2 dice, n times

I'm struggling with some coding-inexperience. The code I've written below, is extremely inconvenient and ugly to look at. My question to you is: How can this be done more efficiently? The way I've ...
4
votes
1answer
58 views

Text-based Adventure-Game Engine

I wanted to create some kind of generic text-based adventure-game engine to see if I could build an interesting puzzle out of it. The idea was to define a mini-language to be able to define the ...
6
votes
0answers
46 views

Battleships Player vs Computer Algorithm

I am a Year 12 student studying CS for my A-Levels. I have had previous Python experience but it is obviously not to professional/industry standard. Therefore, my goal for this review is for my code ...
1
vote
1answer
39 views

Python program for testing the Collatz Conjecture

This is a simple program to test if integers will follow an interesting, improvable statement that if disproven, calls for a bravo. But, ignoring the pretentious poetry, this code allows the user to ...
1
vote
1answer
57 views

Random number guessing game in python

I just started learning Python this week and put this together for my first program (outside of a Hello World one). Does anyone have any feedback/suggestions for improvement for this? I've tried to ...
-1
votes
0answers
17 views

Creating function, if dictionary and list contain same element [closed]

Im trying to create a function that returns true if one or more items in the dictionary are the same as the list Deliverynish. Ive created this so far but when i run it it prints false. As you see in ...
1
vote
0answers
22 views

Django Notification Model with a generic relation

I wanted to implement notifications for my app, so that a user would know if another user, liked, commented on, or followed another user. It works, but I feel like it's very limited which I need to ...
4
votes
1answer
218 views

Converting HEX values to Unicode characters

I have a small bot for social network, which accepts message "unicode XXXX XXXX XXXX ...", where XXXX - HEX values which I ...
5
votes
1answer
66 views

Text search in Python

Whilst self-studying algorithms, I came across the Karp-Rabin rolling hash search algorithm here. I decided to have a go at implementing it in Python: For ease of reading; the data-structure ...
1
vote
1answer
69 views

Printing a list to a file then reassembling said list

This is a GCSE practice problem, to practice for the actual coursework. Computing's my passion and I'd like to impress the examiners (note: any tips would be appreciated) Essentially, this is simply ...
5
votes
1answer
300 views

Find all strings in list which have keywords in it from another list

I a list of strings A and a list of keywords B. Now I want to return all strings from list A which have all keywords from B in it as a new list. ...
2
votes
0answers
26 views

File copy in Python for slow networks (version 2)

This is a follow up of a previous question I have written a file-copy routine, as I experienced unreliable results using standard Python when copying file over very slow networks. The requirements ...
0
votes
0answers
25 views

Return path between graph nodes using breadth-first search

This code is meant to implement a Graph class which has a method that returns a path between 2 nodes using breadth-first search. I'm doing this to improve my style ...