joh*_*4ta 19 python set python-2.7
我正在尝试打印出一组内容,当我这样做时,我在打印输出中得到了set identifier.例如,这是我的输出set(['a', 'c', 'b', 'e', 'd', 'f', 'gg', 'ff', 'jk'])"为下面的代码.我想摆脱这个词set.我的代码非常简单,在下面.
infile = open("P3TestData.txt", "r")
words = set(infile.read().split())
print words
Run Code Online (Sandbox Code Playgroud)
这是我的输出,以便于参考: set(['a', 'c', 'b', 'e', 'd', 'f', 'gg', 'ff', 'jk'])
Mar*_*ers 45
您可以将该集转换为列表,仅用于打印:
print list(words)
Run Code Online (Sandbox Code Playgroud)
或者您可以使用str.join()逗号来加入集合的内容:
print ', '.join(words)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36810 次 |
| 最近记录: |