Python Forum
Modifying / extracting multiple list items simultaneously using variable from range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying / extracting multiple list items simultaneously using variable from range
#1

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]=False
THAT 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.
Reply


Messages In This Thread
Modifying / extracting multiple list items simultaneously using variable from range - by ehammarlund - Dec-06-2017, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 201 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Multiple variable inputs when only one is called for ChrisDall 2 494 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,354 May-22-2023, 10:39 PM
Last Post: ICanIBB
Thumbs Down I hate "List index out of range" Melen 20 3,348 May-14-2023, 06:43 AM
Last Post: deanhystad
  How to check multiple columns value within range SamLiu 2 1,164 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  Finding combinations of list of items (30 or so) LynnS 1 885 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,924 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,622 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  Split string using variable found in a list japo85 2 1,307 Jul-11-2022, 08:52 AM
Last Post: japo85
  How to get list of exactly 10 items? Mark17 1 2,540 May-26-2022, 01:37 PM
Last Post: Mark17

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020