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
19 votes
4 answers
11k views

Converting a large number into something like: 4 Novemnongent

This is not a school project, just something to help me learn some Python! Just looking to see what I can improve on, looking for tips to reduce size & make it a bit easier for the computer to run ...
user155845's user avatar
19 votes
2 answers
3k views

Making my own programming language

This question is really to help me decide on something. I have started development of my own programming language that I am calling DeliciousWaffle (or maybe samscript). So far it looks pretty cool. ...
Sam Tubb's user avatar
  • 539
19 votes
2 answers
3k views

Python backend interview: task management system for workers

I've recently applied to a backend position and I was asked to complete a take-home interview question. I thought the question was rather simple and I completed in about an hour although I was told it ...
DGDD's user avatar
  • 293
19 votes
2 answers
35k views

Simple backup script in Python

Since rsync lacks compression and I'm not a big fan of rdiff, I thought I'd try my own little backup script. Since I'm very ...
magu_'s user avatar
  • 938
19 votes
2 answers
591 views

Newborn pythonic calculator

Let me start off by saying that I have several years of experience in Java, but now I need to learn Python, so I decided to make a calculator as it also is a community challenge. Please review the ...
skiwi's user avatar
  • 10.6k
19 votes
3 answers
1k views

Automatically turn on Computer from Raspberry Pi (based on user presence in home)

I know the code is full of useless data and stylistic and analysis errors and I'd really love and appreciate to have a pro's idea about it so I can learn to code (and think) better. ...
Pitto's user avatar
  • 829
19 votes
2 answers
10k views

A Python wrap-around list

I want to gain experience creating data structures that look and feel like Python builtin types. As a first exercise, I've written a WraparoundList class meant to ...
Endulum's user avatar
  • 383
19 votes
2 answers
11k views

Finding a zero crossing in a matrix

I am trying create an algorithm for finding the zero crossing (check that the signs of all the entries around the entry of interest are not the same) in a two dimensional matrix, as part of ...
Seanny123's user avatar
  • 1,527
18 votes
5 answers
5k views

Printing a list as "a, b, c." using Python

Is there a better way to do this? Assuming very long lists, is this slow and wasteful? ...
jeremy radcliff's user avatar
18 votes
6 answers
3k views

Fraud detection database API server

Rather embarrassingly, I have been coding for some years now, however I feel that I still write code in a very basic way. It is hard to be certain, when many companies often give coding interviews for ...
securityauditor's user avatar
18 votes
4 answers
11k views

20 Ways to do Random Sampling

Here is a (small project) code for practicing Python, it comprises 20 variety of functions that each works to return \$n\$ random samples from a set of data. The code mostly uses the ...
Redsbefall's user avatar
  • 1,132
18 votes
7 answers
43k views

Pythonic way to add each previous element in list

It's a very simple question, but I wonder if there is a more pythonic way to add each previous elements in a list like this (for example with a list comprehension maybe) : ...
Natha's user avatar
  • 347
18 votes
3 answers
5k views

Password Strength Detector

I'm just a beginner in Python. I wrote a simple code that detects the user's password strength, but I feel that it isn't very efficient. How can I improve it? ...
Mahmood Muhammad Nageeb's user avatar
18 votes
5 answers
3k views

Flipping coins performance

This is the Flipping coins problem on CodeChef: There are \$N\$ coins kept on the table, numbered from \$0\$ to \$N - 1\$. Initially, each coin is kept tails up. You have to perform two types of ...
Ukiyo's user avatar
  • 283
18 votes
4 answers
8k views

User login database intended for beginners

I have been working on a small project intended for helping beginner Python programmers getting an idea of what a real project could be like (as opposed to programming exercises and such). This ...
Phrancis's user avatar
  • 20.4k
18 votes
6 answers
4k views

Comma Code - Ch. 4 Automate the Boring Stuff

I am new to programming and currently learning Python using "Automate the Boring" by Al Sweigart. I've just completed the "Comma Code" task in Chapter 4 and would like some ...
benb's user avatar
  • 183
18 votes
6 answers
5k views

Rock, Paper Scissors game in Python

I wrote a simple Rock, Paper Scissors game in Python for class. As a beginner, I would like some input as to how I could abstract or make my code smoother. I feel like the repeated use of ...
Richard Peña's user avatar
18 votes
3 answers
3k views

Providing advice based on user's favourite YouTuber

I have written this code which provides advice based on user's favourite YouTuber. I wonder if there is a better way to do absolutely any of it. Also, if there is any way to optimise it or if there is ...
oscarfrederiksen's user avatar
18 votes
2 answers
97k views

Fastest way to iterate over Numpy array

I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to ...
embert's user avatar
  • 445
18 votes
4 answers
3k views

Hero battle game

This is my first attempt at OOP/classes: a game where you will select a character and use attacks and abilities to defeat the enemy character. I have a few specific questions: I was told that having ...
Claude Fried's user avatar
18 votes
3 answers
4k views

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 ...
Ethan Bierlein's user avatar
18 votes
2 answers
2k views

Simple game of Hangman in Python

I'm starting out with learning how to program in Python and created a Hangman game. I think there is a lot of unnecessary code but I am not sure how to improve it. I wanted to avoid using global ...
Kevin Li's user avatar
  • 181
18 votes
2 answers
3k views

Pancake sort interview with Python

I got asked this question during my interview. You can find information about this question here. Pancake Sort Given an array of integers arr: Write a function flip(arr, k) that reverses ...
NinjaG's user avatar
  • 2,469
18 votes
4 answers
1k views

Discover random web servers and print the index page title

Github repo I wrote this little toy today that probes random web servers and prints out the title of their index page. I'm curious if this code is any good since I'm a bit rusty. get_titles.py <...
Ricky Wilson's user avatar
  • 1,695
18 votes
2 answers
1k views

Given a page of content, determine shortest snippet containing all search phrases (no order required)

A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
ATT's user avatar
  • 183
18 votes
4 answers
39k views

Generate nth prime number in Python

Today I had an interview, where I was asked to solve this problem: Generate nth prime number. Given a signature below, write python logic to generate the nth prime number: ...
Harsha's user avatar
  • 1,291
18 votes
1 answer
34k views

Adjacency List Graph representation on python

I began to have my Graph Theory classes on university, and when it comes to representation, the adjacency matrix and adjacency list are the ones that we need to use for our homework and such. At the ...
inblank's user avatar
  • 387
18 votes
2 answers
20k views

Pokémon style battle game

I haven't been learning Python for too long and I was just wondering how this Pokémon style battle looks? It's based off of this: Turn Based Pokémon Style Game. It's my first proper time using ...
Prendy's user avatar
  • 183
18 votes
2 answers
6k views

Replacing Python Classes with Modules [closed]

I try to avoid using classes in Python as much as possible; if I don't plan on building on it, I don't build it in the first place. It helps me avoid Java-like classes like ...
yurisich's user avatar
  • 654
18 votes
3 answers
4k views

Simulating a two-body collision problem to find digits of Pi

I came across a nice video on 3Blue1Brown's channel that highlights a very indirect way to find the digits in Pi. I'd suggest watching the whole video, but briefly: The setup is as above. A "small" ...
Shirish's user avatar
  • 283
18 votes
2 answers
2k views

Split mp3 of album into individual tracks

Recently, I've been transferring some of my old vinyl records to MP3 files. One of the things I did to make some progress was to automate things, so I initially set things up so that it would record ...
Edward's user avatar
  • 66.5k
18 votes
1 answer
7k views

Plot timings for a range of inputs

When writing Code Review answers, it becomes often necessary to measure how long the modified code takes vs how long the OP's code takes. I needed a nice way to visualize this as a function of the ...
Graipher's user avatar
  • 41k
18 votes
2 answers
3k views

A KenKen puzzle/solver in Python

I've written a simple KenKen puzzle/solver in Python. I'd love some feedback on the design of the puzzle, as well as the architecture for the solver. To model the puzzle, I have the following classes:...
user138440's user avatar
18 votes
1 answer
19k views

Python Executer that kills processes after a timeout

Imagine you want to run a bunch of tasks in parallel, but you can't be sure that all of your tasks will eventually terminate or rather decide to eat up all your memory and CPU time. This should be ...
Klamann's user avatar
  • 351
18 votes
1 answer
6k views

Pretty printing of the numpy ndarrays

Following this idea for pretty printing of numpy ndarrays, I have developed a very primitive prototype: ...
Foad's user avatar
  • 361
18 votes
1 answer
23k views

Myth-busting SQLite3 performance w. pysqlite

I've read most of the posts I could find on optimizing SQLite3 performance, such as: How do I improve the performance of SQLite?, Is it possible to insert multiple rows at a time in an SQLite ...
root-11's user avatar
  • 512
18 votes
1 answer
3k views

Subclassing pathlib.Path

This arises from the SO Question subclassing pathlib.Path. The pathlib sources show that Path, when invoked, selects one of ...
Carel's user avatar
  • 301
17 votes
6 answers
14k views

Verifying IPv6 addresses

While trying to learn Python I stumbled upon a question which asks you to write a code that is able to take an input and verify it to see whether it meets the IPv6 Criteria. I wrote the following ...
Nauman Shahid's user avatar
17 votes
7 answers
4k views

Stack data structure in Python 3

I have implemented a stack in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
Brijesh Kalkani's user avatar
17 votes
6 answers
14k views

Counting the number of consecutive 1's in binary

hackerrank.com Task: Given a base-10 integer, n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation. ...
Kshitiz Koirala's user avatar
17 votes
5 answers
35k views

Reversing a String in Python

I have a simple function that takes a string and reverses it: ...
Michael A's user avatar
  • 1,651
17 votes
5 answers
5k views

Python 3: Why is my prime sieve so slow?

I've implemented the sieve of Eratosthenes in Python 3 as follows: ...
steenbergh's user avatar
17 votes
4 answers
4k views

Python program to scramble MP3 audio

I'm super new to coding. I had a random idea in the car to make this application in order dive head first into learning to code. This is an app to take an MP3 file, "shred it" into pieces (...
Andrew Worley's user avatar
17 votes
3 answers
7k views

Python code that sorts books

I am currently a student just starting to learn python and I need help improving my code for a school assignment. I've already written the code for the program, just need suggestions on how to improve ...
Ash Chia's user avatar
  • 173
17 votes
4 answers
1k views

Sensor logger for Raspberry Pi in a stratospheric probe

I'm writing a Python Script for a Raspberry Pi to measure different sensors. We are planning to send the Pi with that Script running to the stratosphere, so the power usage for the Pi is limited. I ...
Lexu's user avatar
  • 273
17 votes
4 answers
4k views

Beginners Python Hangman Code

I just started learning about Python at school and decided to start this little project with the basic knowledge I have. Most of the code is pretty lengthy and I know there are probably more efficient ...
L0n35's user avatar
  • 315
17 votes
4 answers
25k views

Bitcoin wallet address and private key generator

I wanted to learn how to create a Bitcoin wallet in code. I used as reference this guide which has code examples in JavaScript. I wrote my implementation in Python. Here is the resulting code: ...
Diego Pino's user avatar
17 votes
4 answers
2k views

Make an image where pixels are colored if they are prime

This code creates a black-and-white image of variable size where the n-th pixel is white if n is a prime number and black if it isn't. It works, but I wonder if it is well written or if it could be ...
Dornteufel's user avatar
17 votes
2 answers
3k views

Discount Pokemon Battles

I have decided to create a discount Pokemon battle simulator using a module called guizero. It's basically a wrapper for Tkinter that is easier to learn. Recently, ...
caird coinheringaahing's user avatar
17 votes
3 answers
10k views

Converting numbers to words - Python

I'm new to programming. I tried to find a way to convert numbers into letters with Python. I would like to receive some advice to improve myself. This program works for numbers between 1 and 106 and ...
Roberta Belladonna's user avatar