笨方法!
l = []
dic = {'宝马': {'price': '120000', 'num': '3'},
'奔驰': {'price': '150000', 'num': '7'},
'奥迪': {'price': '100000', 'num': '8'}}
for i in dic:
l_test = list(dic[i].keys())
x = '%s %s %s' % (i, dic[i][l_test[0]], dic[i][l_test[1]])
l.append(x)
x1 = ' '.join(l)
print(x1)
run==>
宝马 120000 3
奔驰 150000 7
奥迪 100000 8
聪明方法!
dic = {'宝马': {'price': '120000', 'num': '3'},
'奔驰': {'price': '150000', 'num': '7'},
'奥迪': {'price': '100000', 'num': '8'}}
for k, v in dic.items():
line = k + ' '
line += v['price'] + ' '
line += v['num'] + ' '
print(line)
run==>
宝马 120000 3
奔驰 150000 7
奥迪 100000 8