How can I skip an index while iterating through a list?

How would I add only elements after a certain index value?
I have

sales_data = [['a',12, 17, 22], ['b',2, 10, 3], ['c',5, 12, 13]]

scoops_sold = 0

for location in sales_data[1:-1]:
  print(location)
  for element in location:
    scoops_sold += element
    
print(scoops_sold)

I want to add all values after the 0 index.
I tried

for location in sales_data[1:-1]:

but the loop skipped over the set list [‘a’,12, 17, 22] and went to [‘b’,2, 10, 3]
thanks in advance for your help!
Dennis

1 Like

Did you try,

for location in sales_data:
  print(location[0])
  for element in location[1:]:
1 Like

Many thanks! I did NOT try that variation.
Again, thank you!

sales_data = [['a',12, 17, 22], ['b',2, 10, 3], ['c',5, 12, 13]]
#add up only the second list 
scoops_sold = 0

for location in sales_data[1:-1]:
  print(location[0])
  for element in location[1:]:
    scoops_sold += element
    
print(scoops_sold)

b
15

1 Like

I would remove the bolded part. We want to iterate the entire sales_data.

Duly noted! Thanks!
Here’s the new code:

sales_data = [['a',12, 17, 22], ['b',2, 10, 3], ['c',5, 12, 13]]

scoops_sold = 0

for location in sales_data:
  #print(location[0])
  for element in location[1:]:
    scoops_sold += element
    
print(scoops_sold)
1 Like