0

规格: Python 3.3.2

我想做的是:

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.

我想出了什么:

# 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)

问题:

当给定两个名称和数字列表时,它返回一个对象的内存地址;看起来像这样:

>>> hrcat()
Please enter names of employees: a,b,c
Please enter employee numbers: 1,2,3
<zip object at 0x7fea10ce4b90>

我想知道为什么它返回内存地址而不是该对象的实际内容?我在网上搜索,但无法找到解决这个问题的答案。感谢您的见解!

4

1 回答 1

2

在 Python 3.xzip中返回一个迭代器(看起来像<zip object at 0x7fea10ce4b90>)。您可以申请list查看内容,

list(zip(name,number))

虽然,如果您只是制作字典,可以忘记列表并直接使用迭代器来填充它,

dict(zip(name,number))
于 2013-06-26T05:05:34.497 回答