我正在尝试创建一个由字典值中的元素组成的字符串。
For line in dictionary:
print 'Category'.format(line['categories'])
这是运行上面代码的结果:
Category = [[u'Cafes', u'cafes'], [u'Pakistani', u'pakistani'], [u'Halal', u'halal']]
Category = [u'American (New)', u'newamerican'], [u'Desserts', u'desserts']]
当我使用它时:
for x in line['categories']:
cat =', '.join(x)
print cat
结果如下:
Cafes, cafes
Pakistani, pakistani
Halal, halal
American (New), newamerican
Desserts , desserts
我想要实现的目标是:
'Cafes, cafes, Pakistani, pakistani, Halal, halal'
American (New), newamerican, Desserts , desserts
答案 0 :(得分:0)
你可以这样做:
ss = ''
for x in line['categories']:
cat =', '.join(x)
ss += cat
print ss