Skip to main content

Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
17 votes
6 answers
1k 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 ...
Slinky's user avatar
  • 829
17 votes
2 answers
5k views

Python bot to answer mathematical questions for a remote server

The MSP Tech Club puts on an annual CTF, available here. I've worked on a solution but was wondering if there's a better way to write it or if I have any particular bad habits showing themselves? The ...
Michael A's user avatar
  • 1,651
17 votes
2 answers
2k views

Yandex programming contest: Alarms

I've tried to solve this challenge about 4 hours during the contest, but all my attempts exceeded the time limit. I tried to solve it with min-heap, but can't pass all the tests. How it can be solved ...
maksadbek's user avatar
  • 281
17 votes
3 answers
5k views

Knapsack branch and bound: forward filter

I've coded branch and bound to solve the knapsack problem, and use a greedy linear relaxation to find an upper bound on a node I'm currently exploring. What I mean by this is that I first sort the ...
rookie's user avatar
  • 1,233
17 votes
3 answers
7k views

Number of Islands in a 2d grid

Recently, I've solved this "Number of Islands" problem on LeetCode, the solution was accepted by the LeetCode OJ. Problem Description Given a 2d grid map of '1's (land) and '0's (water), count the ...
alecxe's user avatar
  • 17.3k
17 votes
2 answers
21k views

Python Back-Up Script

I wrote this script to backup some important files. It backs up the files to a local folder as well as to an external hard drive. It creates a new subdirectory which has its name constructed with ...
asteri's user avatar
  • 4,899
17 votes
2 answers
309 views

Gimme some random passwords

pwgen is a nice password generator utility. When you run it, it fills the terminal with a bunch of random passwords, giving you many options to choose from and ...
janos's user avatar
  • 111k
17 votes
2 answers
896 views

FizzBuzz example in Python for game manual

I'm developing an implementation of the FizzBuzz game as part of an edutainment game for a retro video game platform. In its manual, I want to mention the history of writing a bot for the FizzBuzz ...
Damian Yerrick's user avatar
17 votes
1 answer
18k views

Min/Max Heap implementation in Python

I'm refreshing some of my datastructures. I saw this as the perfect opportunity to get some feedback on my code. I'm interested in: Algorithm wise: Is my implementation correct? (The tests say so) ...
DJanssens's user avatar
  • 1,460
17 votes
1 answer
15k 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 ...
OutOfTheBox's user avatar
17 votes
2 answers
1k views

Python Manga Image Viewer

I'm currently making a manga (read: comic) viewer in Python. This project has been a code-as-you-learn project, because I have been trying to code this as I learned about Tkinter. Python I have known ...
Alex's user avatar
  • 236
17 votes
1 answer
565 views

Warhammer: How many of my attacks will succeed?

Me and a couple of mates sometimes play a game called Warhammer. When playing the game you have options of what each model attacks. This can lead to situations where you know if you shoot with 100% of ...
Peilonrayz's user avatar
  • 43.4k
17 votes
2 answers
13k views

Django Rest Framework - ManyToMany relationship through intermediate model

I'm new to Django and have just started to learn the basics. I have some questions about how to structure the code, how relationships should be written, and where the business logic should live. I ...
Matt's user avatar
  • 311
17 votes
1 answer
506 views

Efficiently selecting spatially distributed weighted points

Background: Motivation behind writing the following code is originated in the area of computer vision. More specifically – image rectification. In order to obtain rectified images, one has to find a ...
Georgy's user avatar
  • 1,939
17 votes
1 answer
623 views

Python Dictionary Black Magic

I am defining a subclass of a the python dictionary object mpCmd where every item is converted to a lambda. The intended usage is that every item in the dictionary ...
cheezsteak's user avatar
  • 2,401
16 votes
6 answers
5k views

A file class for Python

This is the entire code segment. All the functions for file operations are working perfectly. I just need a professional to help me clarify that am following good standards, documentation, etc., ...
jamie_0101's user avatar
16 votes
5 answers
4k views

Finding an element without pair in a list O(n**2)

I'm practicing algorithms, and I just can not come up with a faster solution to this problem, but I'm not hitting the benchmark. Problem: In a large list of large integers, I must find the one element,...
Lorinc Nyitrai's user avatar
16 votes
11 answers
5k views

Check if array has the same number of even and odd values in Python

Task: Complete the following function that determines if the number of even and odd values in an list of Integers is the same. ...
Uncalled Astronomer's user avatar
16 votes
8 answers
12k views

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

I have written an answer to this question on Stack Overflow. To make it easier for you, I have copy-pasted the main question below. Write a program that generates 100 random integers that are ...
Justin's user avatar
  • 2,489
16 votes
5 answers
6k views

Project Euler # 25 The 1000 digit Fibonacci index

The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 ...
user avatar
16 votes
5 answers
8k views

Yu-Gi-Oh cards in Python 3

I made a project in Python 3.7.1 that includes classes to create Yu-Gi-Oh cards. This isn't the entire game; it is just the cards itself. I will create the entire game later. I want feedback on how to ...
Jerry Cui's user avatar
  • 325
16 votes
6 answers
4k views

Sherlock and The Beast

This is my solution to this question from Hackerrank. Given N (<= 100000), find the largest N-digit number such that: The number has only 3 and 5 as its digits. Number of times 3 ...
sundar nataraj's user avatar
16 votes
3 answers
3k views

A Caesar cipher in Python3

This code basically just does a Caesar cipher on the contents of the variable "s" with a shift of 1. Sorry if the comments on the code don't explain it well. I'm quite new to Python and I'm not very ...
Erik D's user avatar
  • 163
16 votes
4 answers
3k views

Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R

A friend of mine recently started learning R, and she complained to me that R is very slow. She was working on Project Euler Problem 7, which asks for the value of the 10001st prime number. For ...
castle-bravo's user avatar
16 votes
4 answers
2k views

Get the first item in a sequence that matches a condition

I've been trying to figure out what's the best, most Pythonic way to get the first element of a sequence that matches a condition. Here are three options: I don't like that I've written ...
deepyaman's user avatar
  • 263
16 votes
6 answers
7k views

Write a program that asks the user to input 10 integers, and then prints the largest odd number that was entered

I am mechanical engineer and have started learning Python from a book called 'Introduction to Computation and Programming Using Python' by John V. Guttag. This is one of the examples. I know that ...
Shreeyash Motiwale's user avatar
16 votes
3 answers
3k views

My 1 Week Python Journey — A Quiz Game that I made in Python

I started my Python Journey almost a week ago from now. I had been following a Youtube tutorial earlier, but switched to Harvard's CS50P instead. I decided on making a little Quiz Game with my ...
Hissan's user avatar
  • 343
16 votes
2 answers
3k views

Translate English to Pig Latin

This is a program for converting English to the pseudo-language Pig Latin. Not the strictest form of Pig Latin but it most likely will accurately output an argument in Pig Latin. I got the idea from a ...
notak's user avatar
  • 605
16 votes
2 answers
2k views

Calculate the Degrees of a Clock Hand Based on Input Time

I'm a novice programmer. I started with Java years back and now mostly use VBA to automate tasks for my internships. I want to graduate from VBA and get into Python/R to properly automate tasks. The ...
sxt_'s user avatar
  • 193
16 votes
1 answer
2k views

Amateur RPG Fun

I am looking for this code to look neater, and if possible, less bulky. I am new to def and to dictionaries, so I think throwing a few of those in here could ...
Amateur Programer's user avatar
16 votes
3 answers
2k views

Newton-Pepys, common birthdays and other probability simulations in Python 3

I have been learning Probability from Statistics 110 and trying to simulate problems that have an unintuitive answer ...
kamalbanga's user avatar
16 votes
3 answers
41k views

List all classes in a package directory

I have a package directory pkg with several classes that I would like to build into a convenient dict property. The structure ...
Mike T's user avatar
  • 263
16 votes
2 answers
2k views

Minecraft block generator

This script is a tool to help minecraft mod development. When you want to add a new block to the game you have to create three json files. This script generates three JSON files in specific locations. ...
Dalton's user avatar
  • 263
16 votes
1 answer
25k views

Decorator to measure execution time of a function

This decorator adds the elapsed time to a function's attributes when applied. My concerns: Is the code pythonic? Could this code be useful? Should I just use the ...
Ricky Wilson's user avatar
  • 1,695
16 votes
1 answer
780 views

Large Number Limit Extravaganza

I am writing a program that computes $$n-n \cdot \left(\prod_{i=1}^n (1-\frac{1}{p_i})\right)$$ which is rewritten in my code as: $$\left(1-\left(\prod_{i=1}^n(1-\frac{1}{p_i})\right)\right) \cdot ...
Linus Rastegar's user avatar
16 votes
1 answer
5k views

Increasing speed of BWT inverse

I think understanding basic data compression and pattern finding / entropy reduction primitives is really important. Mostly the basic algorithms (before the many tweaks and optimizations are made) are ...
Cris Stringfellow's user avatar
16 votes
2 answers
37k views

Conway's Game of Life in Python

Here's my Python implementation of Conway's Game of Life: ...
Tim Vermeulen's user avatar
16 votes
2 answers
2k views

Car computer in python / GPS tracking

I have an old car that I use for long distance driving and have coded an onboard computer based on a Raspberry Pi 3 and a few other modules. It's my first project in Python and while I've already ...
Damien Bourdonneau's user avatar
16 votes
3 answers
73k views

Set a default if key not in a dictionary, *or* value is None [closed]

Let's say I have a key 'messages' that is usually a list, but might be None, or might not be present. So these are all valid inputs: ...
Kevin Burke's user avatar
16 votes
1 answer
38k views

Efficiently filter a large (100gb+) csv file (v3)

I'm in the process of filtering some very(!) large files (100gb+): I can't download files with a lower granularity. This is a followup from this question. The problem is as follows: I need to filter ...
MattV's user avatar
  • 698
16 votes
3 answers
1k views

Razzle Dazzle simulator

Inspired by the video from Scam Nation and James Grime from Numberphile, I tried to make a Razzle Dazzle simulator. Razzle Dazzle is a scam in the form of a game. Per turn, the player pays a fee and ...
user2966394's user avatar
16 votes
1 answer
1k views

Barnsley's Fern

I recently watched the Numberphile video entitled 'Chaos Game', and in that they showed how Sierpinski's triangle could be made from random numbers. But at the end of the video, they showed how this ...
George Willcox's user avatar
16 votes
2 answers
3k views

ECDH implementation in python

I wrote an implementation of elliptic curve Diffie-Hellman key exchange in python. I would like to know if I could make it faster, cleaner or more secure: ...
Aemyl's user avatar
  • 760
16 votes
3 answers
1k views

Wheel based unbounded sieve of Eratosthenes in Python

Answering this SO question recently, I've developed the following code (based on a well-known Active Code recipe, as discussed here): ...
Will Ness's user avatar
  • 1,026
16 votes
1 answer
3k views

Rock Paper Scissors Lizard Spock

I got some good feedback from the last code I posted which I have incorporated in to this project (enum, try, f string formatting), so again just looking for some feedback on how the code could be ...
CelestialMark's user avatar
16 votes
1 answer
390 views

Solve the phase state between two haplotype blocks using markov transition probabilities

I have spent about more than a year in python, but I come from biology background. I should say I have got some understanding of for-loop and nested-for-loop to workout the solution to the problem I ...
everestial's user avatar
16 votes
1 answer
813 views

JediScript - May the 4th be with you

In honor of Star Wars day, I've put together this small Python program I'm calling JediScript. JediScript is essentially a scrapped-down version of BrainFuck without input or looping. Here are the ...
Ethan Bierlein's user avatar
16 votes
2 answers
868 views

Using lots of regex substitutions to tokenize text

I authored a piece of code that was merged into the nltk codebase. It is full of regex substitutions: ...
alvas's user avatar
  • 705
16 votes
1 answer
3k views

Pure python range implementation

I implemented class Range as an equivalent to Python built-in range for practicing purposes. No features were added. Hope it ...
sanyassh's user avatar
  • 315
16 votes
1 answer
7k views

Streaming H264 video from PiCamera to a JavaFX ImageView

I'm currently working on a robotics application where a video feed is being displayed from a Raspberry Pi 3. I've been working on a way to stream the video directly into JavaFX (the rest of the UI is ...
flakes's user avatar
  • 1,925

1
3 4
5
6 7
311