I am new to python and am trying to grasp a few things. I would like to create a dictionary from two lists. I have two sets of data:
Person | Name
--------|--------
1 | Jimmy
2 | Mike
3 | Stanley
4 | Will
I have both of these in lists, one called “person” and one called “name”. I do this in a script which runs through multiple files to pull the data. each list is a different length with different data in it. Essentially, what I want to do is print the data as like this:
1 \t Jimmy
2 \t Mike
3 \t Stanley
4 \t Will
I pull the data from an xml file and here is the code I use to pull the data:
for people in xml.iter('people'):
person.append(people.find('person').text)
name.append(people.find('name').text)
So far the script works great and I can print out the two lists separately. What I don’t know how to do is print them out together and so my thought is to store them to a dictionary instead, but I don’t really know how to do that.
If you just want to print the two lists you can use
zip(doc)you can use the same form to put the pairs in a dictionary (after you have the lists)
and then print