I am going through the "Head First" Learn to Program text for python 2.7, and as I was working through one of the exercises. It gave me a clue to multiple assign a line of data while splitting it. And since I could not guess it, I went to the solution, and I do not understand the solution.
I am running the latest python in the native IDLE
line = "101;Johnny 'wave-boy' Jones;USA;8.32;Fish;21"
display = {}
(display['ID'], display['Name'], display['Country'], display['Average'], display['Board'], display['Age']) = line.split(';')
I do not understand what is going on with the multiple assignments in the code above. How is the splitting making key and value pairs?
What role are the braces playing in this?
When I guessed for multiple assignments I imagined this:
(ID, Name, Country, Average, Board, Age) = line.split(;)
for a, b, c, d, e, f in line:
display[ID] = Name, Country, Average, Board, Age
I thought that I could assign several values to one key, and just index or iterate the has with the keys() or items() method.