Python中的连接,连接列表和字符串

Jon*_*han 0 python string list concatenation

我不确定这是否是正确的语法,但我想在列表中打印出一个特定的元素.

user,activity,data=readfile('data.txt')
kclust,clusters=kcluster(data,k=3)
for i in range(len(kclust)):
    print "Cluster %d: ??" % (i+1,clusters[i])
    print [[userobjectIds[r] for r in kclust[i]][:3]]
    print 
Run Code Online (Sandbox Code Playgroud)

'??' 是我尝试%d和%o但得到:"TypeError:%o格式:需要一个数字,而不是列表"

Fel*_*ing 5

你可以使用%r:

'r':String(使用转换任何Python对象repr()).

print "Cluster %d: %r" % (i+1,clusters[i])
Run Code Online (Sandbox Code Playgroud)