Answer to Question #264375 in Python for Vera warren

Question #264375

The error of this code is Expected an indented block.

kindly check and show the correct code


main_list = []

x = {}

field_names = [ "City name", "Area", "Population", "Annual Rainfall"]



list1 = [



 ["Adelaide", 1295, 1158259, 600.5],

 

 ["Brisbane", 5905, 1857594, 1146.4],

 

 [ "Darwin", 112, 120900, 1714.7],

 

 ["Hobart", 135, 20556, 619.5],

 

 ["Sydney", 2058, 4336374, 1214.8],

 

 ["Melbourne", 1566, 3806092, 646.9],

 

 ["Perth", 5386, 1554769, 869.4]

 ]



for i in range(0, len(list1)):



 for key in field_names:



 for value in list1[i]:



 x[key] = value



 list1[i].remove(value)

 break

main_list.append(x)

print(main_list)


1
Expert's answer
2021-11-11T07:30:23-0500
main_list = []


x = {}


field_names = [ "City name", "Area", "Population", "Annual Rainfall"]






list1 = [






 ["Adelaide", 1295, 1158259, 600.5],


 


 ["Brisbane", 5905, 1857594, 1146.4],


 


 [ "Darwin", 112, 120900, 1714.7],


 


 ["Hobart", 135, 20556, 619.5],


 


 ["Sydney", 2058, 4336374, 1214.8],


 


 ["Melbourne", 1566, 3806092, 646.9],


 


 ["Perth", 5386, 1554769, 869.4]


 ]






for i in range(0, len(list1)):






  for key in field_names:





#Below lines indented
    for value in list1[i]:






      x[key] = value






      list1[i].remove(value)


      break


main_list.append(x)


print(main_list)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS