Python Forum
How can I increment a List item with in a "for in"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I increment a List item with in a "for in"
#1
This is likely Python 101.

I have searched for a straight forward simple answer to no avail.
How can I increment a list item while inside a "for x in List" loop.
I want to process two list items in sequence based on the first item having a given value. Then move on through the loop structure.

items = [ "Thing", "apple", "dog", "house", "Thing", "bugs", "ducks", "rabbits"]
#  Start my loop over the list
for i in items:    
	if i == "Thing":   
		print(i) 
		# increment(i)??
		print(i) # this should print the next item in the list after the last "Thing"
		
# output I want is:
# Thing 
# apple
# Thing
# bugs
Reply


Messages In This Thread
How can I increment a List item with in a "for in" - by msteffes - Aug-13-2019, 09:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help to increment a third list hermine 7 1,272 Nov-29-2022, 04:19 PM
Last Post: perfringo
  mysql id auto increment not working tantony 10 2,312 Oct-18-2022, 11:43 PM
Last Post: Pedroski55
Question Finding string in list item jesse68 8 1,801 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  how to easily create a list of already existing item CompleteNewb 15 3,386 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,555 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  count item in list korenron 8 3,374 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  Character Increment AnokhiRaaz 1 2,462 Apr-22-2021, 04:29 AM
Last Post: buran
  Time.sleep: stop appending item to the list if time is early quest 0 1,847 Apr-13-2021, 11:44 AM
Last Post: quest
  Increment text files output and limit contains Kaminsky 1 3,138 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  How to run a pytest test for each item in a list arielma 0 2,325 Jan-06-2021, 10:40 PM
Last Post: arielma

Forum Jump:

User Panel Messages

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