Dec-06-2017, 06:02 PM
(This post was last modified: Dec-06-2017, 06:04 PM by ehammarlund.)
I am a beginner(**) trying to figure out how to put multiple items in/out of lists using variables. To demonstrate, I'm trying to make a prime sieve. [u]My comments/questions bolded below.
highnum=1000000 #the number you’re checking to, here it's a million, could be anything erik=list(range(1,highnum) #create a list to sieve it def sieve(x): erik[(2x)::x]=False #I CAN’T FIGURE OUT HOW TO ASSIGN MULTIPLE LIST VALUES AT THE SAME TIME. CAN IT BE DONE? It doesn’t seem to want to accept a variable in the list definition so perhaps not…?
I ALSO TRIED:
erik.insert[(2x)::x]=FalseTHAT DID NOT WORK EITHER. SIGH.
IF I CAN GET IT TO WORK, THEN IN THEORY I CAN DO THIS:
for y in range (1,((highnum/2)+1)): sieve(y) sieveoutput=(Erik[] where erik!= False)#WILL THIS WORK/WHY WON’T THIS WORK? HELP!
OR DO I NEED TO DO IT LIKE THIS?
For z in range(1,highnum): iferik(z) != False: sieveoutput.append erik[z]Sorry about the very low-level questions;I literally started to learn Python three days ago. Thanks in advance for any pointers.