Extract the unique values into a set, then join those into a single string:
unique = {t[0] for t in record[1]}
print '{}:{}'.format(record[0], ','.join(unique))
Demo:
>>> record = (u'U9', [(u'U2', 1.0), (u'U10', 0.6666666666666666), (u'U2', 1.0)])
>>> unique = {t[0] for t in record[1]}
>>> print '{}:{}'.format(record[0], ','.join(unique))
U9:U10,U2
Note that sets are unordered, which is why you get U10,U2
for this input, and not U2,U10
. See Why is the order in dictionaries and sets arbitrary?
If order matters, convert your list of key-value pairs to an collections.OrderedDict()
object, and get the keys from the result:
>>> from collections import OrderedDict
>>> unique = OrderedDict(record[1])
>>> print '{}:{}'.format(record[0], ','.join(unique))
U9:U2,U10