应用str函数后仍无法打印对象

时间:2019-07-22 23:52:58

标签: python-3.x string function

我正在尝试遵循https://programminghistorian.org/en/lessons/counting-frequencies上的教程,但是str函数不会在最终声明中将文本转换为可打印格式。我正在运行python 3.5.5。

wordstring = 'it was the best of times it was the worst of times '
wordstring += 'it was the age of wisdom it was the age of foolishness'

wordlist = wordstring.split()

wordfreq = []
for w in wordlist:
    wordfreq.append(wordlist.count(w))

print("String\n" + wordstring +"\n")
print("List\n" + str(wordlist) + "\n")
print("Frequencies\n" + str(wordfreq) + "\n")
print("Pairs\n" + str(zip(wordlist, wordfreq)))

对于最终的印刷品,我应该看到

的输出
    Pairs
    [('it', 4), ('was', 4), ('the', 4), ('best', 1), ('of', 4),
    ('times', 2), ('it', 4), ('was', 4), ('the', 4),
    ('worst', 1), ('of', 4), ('times', 2), ('it', 4),
    ('was', 4), ('the', 4), ('age', 2), ('of', 4),
    ('wisdom', 1), ('it', 4), ('was', 4), ('the', 4),
    ('age', 2), ('of', 4), ('foolishness', 1)]

但我实际上在看到

    Pairs
    <zip object at 0x000000000495BE08>

0 个答案:

没有答案