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

learn more… | top users | synonyms

2
votes
0answers
27 views

Karger's min-cut algorithm implemented in python

I implemented Karger's algorithm with the function find_min_cut and it works, but I don't feel satisfied with the code I wrote. ...
0
votes
0answers
9 views

Renames file-name references inside files in a directory

The filenames.txt contains all the names of the files that you want to change in a given directory. It is generated by: ...
5
votes
0answers
19 views

Regex-guided crawler that downloads regex-matching images up to a crawling level

This is one simple crawler that downloads images from websites, the website's URL to be crawled to must match the regex, as well as any image-to-download's URL. (Also, I know, I made my own thread ...
1
vote
2answers
23 views

Points and segments solution

Task: Given a set of points on a line and a set of segments on a line. The goal is to compute, for each point, the number of segments that contain this point. Input Format The first ...
1
vote
1answer
36 views

The base-ten value of n-base number with Python

To start off I'd like to note I am aware of int(val, base). My goal was to write a short function capable of taking in a base int...
6
votes
1answer
68 views

Using the mouse to avoid asteroids and black holes

I have finished my first project for Python. I would be very grateful if you could check it and give me some feedback. Just simple game with possibility of replay. There are probably lots of mistakes ...
2
votes
1answer
38 views

Encoding a list of frequencies as WAV audio

This code gets a list of signals with predefined frequency from struc.num I need to encode it to wave format, so i use this code. This works, but i dont sure it is a correct decision to encode like ...
5
votes
3answers
60 views

Snakes on a prime

The challenge is to find and print the largest palindrome prime under 1000. ...
15
votes
3answers
829 views

Generalized Project Euler 1: A sledgehammer to crack a nut

The problem Project Euler 1 is one of the most asked questions on site. However I wanted to solve the more general problem of division. Multiples of a list If we list all the natural numbers ...
5
votes
1answer
42 views

Python comparing a string or list of strings to a string or list

I'm using a selfmade python program for learning new words in new languages. Originally I made this program for a university course but now I'm just trying to imrove it and make the code "prettier" ...
8
votes
5answers
1k views

“Guess the Number” game in Python

I have been using Python 3 to learn programming, and this is a very basic task, but I want to gain good programming patterns/habits at the very beginning. The program will first randomly generate a ...
1
vote
0answers
24 views

SI1145 Adafruit UV Sensor Library porting from Ardunio to Python SMBUS [on hold]

First post here. I originally asked this question on the Raspberry Pi Exchange because of its specific nature but it was suggested it would be better seen here so here goes. I have spent the day ...
2
votes
0answers
29 views

Simple image scraping

I wrote this code over the last few days and I learned a lot, and it works as I expect. However I suspect it's woefully inefficient: ...
2
votes
2answers
22 views

__str__ method for a tic-tac-toe board

I am making my first object-oriented program in python and I am having trouble with the __str__ part of Board() class. I want it ...
5
votes
2answers
51 views

Non-repeatability (plagiarism and time travel)

I heard/read that writers of texts can be recognized by counting their used words and compare these to previous works. As a code kata I experimented with this a bit and found some disturbing facts. ...
1
vote
1answer
27 views

Python Decimal to Binary converter

There is no input validation for this, but that aside, I would appreciate it if anyone could help me improve the logic of this script. ...
2
votes
0answers
10 views

Creating a Kinesis stream, Firehose, and lambda event source from config file

I'm in the process of writing a python script for automating a data ingestion pipeline using Amazon Web Service's Kinesis stream, Firehose and lambda. This is my first stab at writing Python, but I do ...
2
votes
1answer
19 views

Start and end times of recurring events

I'm working on a function that returns a specific set of times for a given timezone and a given frequency; day, week, month. For any given timezone and a frequency the function will return the ...
2
votes
1answer
20 views

Exponential backoff generator

Exponential backoff in the context of various networking protocols looks something like this: When a collision first occurs, send a “Jamming signal” to prevent further data being sent. ...
3
votes
0answers
16 views

Memoizing decorator with retries, part 2

A while ago I asked this question Memoizing decorator that can retry and then promptly forgot about it. I more recently saw Python decorator for retrying w/exponential backoff and wanted to add ...
10
votes
7answers
2k views

French animal generator

I'm learning Python. I'm making a random animal generator, from 5 txt files. Each file is a list of words for respectively the specie of the animal, an adjective, an origin, and a bodypart with a ...
-5
votes
0answers
20 views

Making a object move when pressing a key. Python Tkinter: PONG game [on hold]

So I'm trying to do a Pong game but I'm stuck with the "moving of paddle" thing. I've managed to do so that the method "moving" recognizes with i've pressed w or s for up or down commands. But I can't ...
4
votes
1answer
51 views

Custom Python 'Server Status Checker'

I've written a home-grown solution for checking the status of my servers. This is both an exercise for me in learning further about Python, but it's also critical to status-checking critical things ...
1
vote
1answer
219 views

Validating that only certain values are unset

I am checking data output in some testing code, and only some fields can be None, but I think this can be better: ...
3
votes
1answer
39 views

Count digits in a given number using recursion

Here is my code that finds the number of digits in a given integer (either positive or negative). The code works and results in expected output. ...
1
vote
0answers
15 views

Scraping after login using scrapy

I just finished a scraper in python using scrapy. The scraper logs in to a certain page and then scrapes a list of other pages using the authenticated session. It retrieves the title of these pages ...
3
votes
1answer
19 views

Basic call-and-response Slack bot

I'd love thoughts on how to make this more elegant. I'm planning to add some additional functionality, but basically this is just my first pass at creating a pythonic Slack bot from scratch. You ...
3
votes
1answer
67 views

Filtering a list for certain strings

I want to create a function that filters a list with the following criteria: Strings containing numbers should be removed Strings containing only one word and first letter of the word is not ...
5
votes
5answers
151 views

Counting pairs of relatively prime numbers

Problem from Hacker Earth: Inverted GCD: Given an array a of \$N\$ numbers , you have to find the number of pair of indices \$i\$ and \$j\$ that satisfy the following relation: \$i &...
8
votes
2answers
1k views

Reduce number of operations to get one array value

I can't wrap my head around that. There seem to be a lot of redundancy, and even if it is not called called more than ten times in the main loop, I still find it hard to swallow that it loops through ...
3
votes
1answer
65 views
4
votes
2answers
69 views

Compare files by name in two folders A and B and delete duplicates from folder A

I wrote my very first Python program to answer a Super User question. I'm wondering how the application can be rewritten to make it as pythonic as possible. Unit test ...
2
votes
1answer
159 views

Python binary to decimal converter

Any ideas how I could improve this? I already know that there is no checking for anything other than a 1, so you can enter a 2 ...
2
votes
1answer
49 views

Python decorator for retrying w/exponential backoff

This is my first decorator in Python! I found some of it on the internet but have tweaked it to our needs. Here is the couple concerns of mine: Multiple python version compatibility Is grabbing ...
1
vote
1answer
51 views

Sum over selected numpy.ndarray column and write to a file

I am trying to write the sum of selected NumPy array column and write to a file. The following code snippet is working fine: ...
2
votes
1answer
76 views

Prime number checker in Python 3 - follow-up

I have updated my code from the last time it got reviewed. If anyone has some more suggestions on how I can improve this and/or make it faster it would be appreciated! ...
1
vote
0answers
33 views

Properties Manager

I'm trying to do a property manager that loads a yaml file and stores all the properties in a db. I'm not sure if this would be the right approach. Any suggestions? ...
5
votes
1answer
81 views

Clustering nodes with Hamming distance < 3

I want to speed up the following code, which is from an algorithm class. I get a list of 200000 nodes where every node is a tuple of the length of 24 where every item is either a 1 or 0. These ...
7
votes
1answer
46 views

A CNN in Python WITHOUT frameworks

Here's some code that I've written for implementing a Convolutional Neural Network for recognising handwritten digits from the MNIST dataset over the last two days (after a lot of research into ...
4
votes
2answers
31 views

Invoicing Program Python

This is my invoicing program I made for myself to keep track of purchases people made from me. (Yes I know eBay does this for me but I wanted to see what I could make.) Basically it can search the ...
1
vote
2answers
26 views

Countdown Timer for Tests

I created this countdown timer as a tool to count down the remaining time on a test a few months ago. However, I looked at the code today and it looks like it needs some improvement, but I'm not sure ...
-3
votes
0answers
18 views

Count Inversions Issue - Python [closed]

I am not what is wrong with this algorithm to count the number of inversions. Please can someone look at this and point the issue ...
3
votes
1answer
39 views

Python program that takes input and runs queries on a mySQL database on it

I've been slowly learning Python so I want to know what the most Python-esque way of doing things are. The scenario is that I'm connected to a database with a Customer and a SalesRep table in a ...
2
votes
3answers
44 views

HackerRank “Nested Lists” Code

I completed the "Nested Lists" challenge on HackerRank, and would love any feedback on my code. My program is fed text with the number of students in a classroom, the name of a student, and their ...
2
votes
2answers
35 views

Text font size adapting to space

In order to practice my programming skills, I am trying to implement a Button class, to use in pygame. I know there are libraries like PGU, I do this to improve in programming. I spent a bit of time ...
7
votes
2answers
120 views

Mad Libs Generator

I created this Mad Libs generator, but I don't know how to get the value of the key "ans" into a format string tuple. I feel like it's not Pythonic and that it's very convoluted and over-complicated. ...
10
votes
1answer
894 views

Solving for Bananas

This code creates a problem for the user to solve (very simple problem) it will then check if the user has got it right and will say so. ...
-5
votes
0answers
19 views

Caesar Cipher Python 3: IndentationError? [closed]

I am attempting to create a simple python script which will either encrypt or decrypt a phrase entered. Here is the source code: ...
4
votes
2answers
61 views

Prime number calculator in Python 3.4.1

I have only been coding for a short time and I have written these two functions and am looking to optimise them. If anyone could point out things that could be done better it would be much appreciated....
-1
votes
0answers
18 views

python imports too verbose [closed]

I am working on a python game and the import statements are too verbose and redundant. How can I make them lesser so? This is my directory tree: ...