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
#3
Thanks! I am trying to begin at index value= 2x (whatever x is as per the range loop) and replace the number in the list with "False" throughout the whole list, every X steps.

As an example for x=3, the list
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
would become(new changes underlined)
1,2,3,4,5,False,7,8,False,10,11,False,13,14,False,16,17,False,19,20

and if I then ran that same function for x=5 it would become (new changes underlined):
1,2,3,4,5,False,7,8,False,False,11,False,13,14,False,16,17,False,19,False

(yes, I know that my actual code includes x=2 and x=4, but I left them out because they make it hard to illustrate what I'm doing.)
Eventually the list would only contain "False" and primes.

I can then either output a list of primes if I want them or can leave the list as-is for a very quick way to check the primacy of a number.
If I succeed, I'll choose which output to use later on. I don't know yet whether there's a material speed difference in
a) testing "is list[index]==False"
versus
b) testing "is [item] contained in list"
Reply


Messages In This Thread
RE: Modifying / extracting multiple list items simultaneously using variable from range - by ehammarlund - Dec-06-2017, 06:46 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 228 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Multiple variable inputs when only one is called for ChrisDall 2 515 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,397 May-22-2023, 10:39 PM
Last Post: ICanIBB
Thumbs Down I hate "List index out of range" Melen 20 3,435 May-14-2023, 06:43 AM
Last Post: deanhystad
  How to check multiple columns value within range SamLiu 2 1,204 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  Finding combinations of list of items (30 or so) LynnS 1 901 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,968 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,677 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  Split string using variable found in a list japo85 2 1,333 Jul-11-2022, 08:52 AM
Last Post: japo85
  How to get list of exactly 10 items? Mark17 1 2,580 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