-1

I have:

master_list = [['001', '15\n', '963789', '40\n', '741239', '80\n', '985697', '80\n', '854698', '35\n', '965874', '10\n'],
 ['002', '25\n', '326574', '65\n', '944223', '40\n', '312689', '45\n', '225869', '80\n', '789654', '35\n'],
 ['003', '10\n', '857963', '50\n', '253698', '40\n', '965478', '50\n', '186458', '40\n', '351296', '40\n'],
 ['004', '20\n', '675964', '40\n', '612985', '40\n', '653674', '35\n', '957296', '50\n', '852169', '40\n'],
 ['005', '13', '246912', '40\n', '371956', '40\n', '819736', '40\n', '915745', '50\n', '197548', '40']]

am trying to unpack as:

for a,b,c,d,e, in master_list:
        print(a,b,c,d,e)

getting exception:

ValueError: too many values to unpack (expected 5)

why is that. I see nothing wrong

Robert
  • 10,126
  • 19
  • 78
  • 130

2 Answers2

2

The error is right, you have 12 items in the nested lists and you're only providing 5 variables to unpack into. If you are simply printing them, you can do:

for l in master_list:
    print(*l)
sshashank124
  • 31,495
  • 9
  • 67
  • 76
0

in python3 you could adress the issue of arbitrary lenght this way:

for a,b,c,d,e,*_ in master_list:
    print(a,b,c,d,e)
yemu
  • 26,249
  • 10
  • 32
  • 29