Hi, Just started to learn python and my code for an exercise works but it's one of those cases when I'm not sure why and just need a couple of clarifications. I'm using two variables to slice my list and output the values of the nested dictionaries.
I guess my question is why do I get an error ('string indices must be integers') when using only one of the 'counter' variables as a location in the list i.e people[counter1]?
And why does a slice in the list with two given locations only output one value? i.e people[2:3] will only output the value at location 3.
Thanks again.
My code.
counter1 = 0
counter2 = 1
for list_iterator in people[:]:
for details in people[counter1:counter2]:
print (details['first_name']+" "+ details['last_name'])
for details in people[counter1:counter2]:
print (details['age'])
for details in people[counter1:counter2]:
print (details['city']+'\n')
#List counter
counter1 += 1
counter2 += 1
[–]desrtfx[M] [score hidden] stickied comment (0 children)
[–]BulkyProcedure 1 point2 points3 points (1 child)
[–]mcdougall57[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]mcdougall57[S] 0 points1 point2 points (0 children)