Jonathan
Jonathan

Reputation: 753

Concatenation in Python, concatenating lists and strings

i'm not sure if this is the correct syntax to do this, but i want to print out a specific element in a list.

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 

the '??' is where i've tried %d and %o but get: "TypeError:%o format:a number is required, not list"

Upvotes: 0

Views: 1190

Answers (2)

Charles Brunet
Charles Brunet

Reputation: 23110

I don't know about kcluster function, but it seems it returns a list, not a number. Alternatively, you could try:

print "Cluster %d:"%(i+1), clusters[i]

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816262

You can use %r:

'r': String (converts any Python object using repr()).

print "Cluster %d: %r" % (i+1,clusters[i])

Upvotes: 5

Related Questions