Python Forum
for loop and list populating
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop and list populating
#1
Ok I built a very basic caesar wheel...(w/out modules/classes). There was more trial/error than I care to admit Tongue . But, I came across something I couldn't figure out. Here is the relevant snippet.

base_wheel = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z']

new_wheel1 = []
new_wheel2 = []

spinner1 = random.randint(0,25)
spinner2 = spinner1

for b in base_wheel:
	new_wheel1.append(base_wheel[spinner1])
	spinner1 -= 1#no problem with decrementing
for b in base_wheel:
	new_wheel2.append(base_wheel[spinner2])

	#why does += 1 (below) go over range?  I am looping elements of base_wheel
	#loop is finite so spinner2 must also terminate
	spinner2 +=1
very puzzling to me... thx in advance...
Reply


Messages In This Thread
for loop and list populating - by mepyyeti - Apr-12-2018, 01:23 AM
RE: for loop and list populating - by buran - Apr-12-2018, 02:55 AM
RE: for loop and list populating - by Larz60+ - Apr-12-2018, 02:58 AM
RE: for loop and list populating - by buran - Apr-12-2018, 03:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Populating an array dynamically zxcv101 1 1,160 May-17-2022, 11:24 AM
Last Post: deanhystad
  Appending to list of list in For loop nico_mnbl 2 2,378 Sep-25-2020, 04:09 PM
Last Post: nico_mnbl
  Append list into list within a for loop rama27 2 2,406 Jul-21-2020, 04:49 AM
Last Post: deanhystad
  Populating a timetable with subjects brittocj 1 1,819 May-02-2019, 07:00 AM
Last Post: buran
  loop through list or double loop 3Pinter 4 3,469 Dec-05-2018, 06:17 AM
Last Post: 3Pinter
  Populating Array2 from Array1 PappaBear 1 2,068 Aug-22-2018, 04:30 AM
Last Post: PappaBear
  Populating a list with divisors RedSkeleton007 1 2,195 Aug-21-2018, 12:52 AM
Last Post: Larz60+
  Write a for loop on list of lists without changing the shape of the main list Antonio 3 3,785 Jun-19-2018, 02:16 AM
Last Post: ichabod801
  populating csv and searching the file mepyyeti 1 2,973 Apr-26-2018, 03:02 AM
Last Post: woooee
  For looping over a list, editing the list from inside the loop? Krookroo 3 3,970 Sep-04-2017, 05:08 PM
Last Post: Krookroo

Forum Jump:

User Panel Messages

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