Specs: Python 3.3.2
What I was trying to do:
Create a simple name and employee number dictionary application. Have the user enter a list of names and employee numbers. Your interface should allow a sorted output (sorted by name) that displays employee names followed by their employee numbers.
What I came up with:
# enter a list of names of employees
# enter a list of employee numbers
# zip them together
def hrcat():
name = input('Please enter names of employees: ')
number = input('Please enter employee numbers: ')
output = zip(name,number)
print(output)
Question:
When given two lists of names and numbers, it returns the memory address of an object; something looks like this:
>>> hrcat()
Please enter names of employees: a,b,c
Please enter employee numbers: 1,2,3
<zip object at 0x7fea10ce4b90>
I wonder why it returns the memory address instead of the actual content of that object? I googled online but wasn't able to find answers addressing this question. Thank you for your insights!
In Python 3.x zip
returns an iterator (which looks like <zip object at 0x7fea10ce4b90>
). You can apply list
to view the contents,
list(zip(name,number))
Although, if you are just making a dictionary, can forget about the list and use the iterator directly to populate it,
dict(zip(name,number))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.