我有字典作为输入,例如
输入词典:
{'location': {'street1': 'Deborah Throughway', 'city': 'East Betty', 'stateOrProvince': 'AK', 'postcode': '50545', 'country': 'US'}}
和预期输出为:
'SiteAddress': 'Deborah Throughway, East Betty, AK, US, 50545'
我尝试了list(dictionary['location'].values())
,但得到
{'SiteAddress': ['Deborah Throughway', 'East Betty', 'AK', '50545', 'US'] }
请提出我在做错什么以及如何获得预期的输出
答案 0 :(得分:0)
data = {'location': {'street1': 'Deborah Throughway', 'city': 'East Betty', 'stateOrProvince': 'AK', 'postcode': '50545', 'country': 'US'}}
def main():
loc = data['location']
address = ",".join([loc['street1'], loc['city'], loc['stateOrProvince'], loc['country'], loc['postcode']])
print("SiteAddress: {0}".format(address))
if __name__ == '__main__':
main()
输出:
SiteAddress: Deborah Throughway,East Betty,AK,US,50545