Loading [Contrib]/a11y/accessibility-menu.js
Practice
Compete
Contribute
Learn
Log In
Sign Up
Python Prime Number Sieves
sanghan
8,352 views
01
Introduction
02
Algorithm
03
Implementation
3/3
Implementation
Previous:
Algorithm
Implementation
Python Sieve
1
2
3
4
5
6
7
8
9
10
def sieve(n: int) -> list:
"""
Sieve away and only primes are left.
"""
primes = 2*[False] + (n-1)*[True]
for i in range(2, int(n**0.5+1.5)):
for j in range(i*i, n+1, i):
primes[j] = False
return [prime for prime, checked in enumerate(primes) if checked]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
16
1
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
Suggested playgrounds
Recueil d'exercices pour apprendre Python au lycée
By
M_C
306.6K
160
How to build a chatbot in less than 50 lines of code
By
[CG]Maxime
15.8K
76
Longest substring in Python
By
tsv
6,349
11
Computing with Data
By
elgeish
182.9K
36
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants
Keyboard Shortcuts:
?
Show / hide this help menu
×