-3

I have the following lists:

[['Not stated', 128913], ['Response outside scope', 8457], ['Response unidentifiable', 17565], ['Other fuel(s)', 8184], ['No fuels used in this dwelling', 60819], ['Solar power', 603], ['Home heating oil', 24], ['Coal', 19203], ['Wood', 513561], ['Gas', 276666], ['Electricity', 1150047]]

How to write a for/in loop to print the second elements of all the Lists?

I have tried several codes posted in this website and couple others, but didn't work. I am a new in programming and studying this for my studies.

eshirvana
  • 23,227
  • 3
  • 22
  • 38

2 Answers2

0

As @mkrieger1 suggested:

lists = [['Not stated', 128913], ['Response outside scope', 8457], ['Response unidentifiable', 17565], ['Other fuel(s)', 8184], ['No fuels used in this dwelling', 60819], ['Solar power', 603], ['Home heating oil', 24], ['Coal', 19203], ['Wood', 513561], ['Gas', 276666], ['Electricity', 1150047]]

for item in lists:
    print(item[1])
pugi
  • 323
  • 1
  • 12
0

It looks like tally of survey responses, so I'll assume that is the context

for fuel, responses in survey:
    print(responses)

Using two or more variables in the for loop is known as multiple assignment