Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用花括号垂直打印{,}_Python_Json_Python 3.x_List_Function - Fatal编程技术网

Python 用花括号垂直打印{,}

Python 用花括号垂直打印{,},python,json,python-3.x,list,function,Python,Json,Python 3.x,List,Function,我需要打印“国家/地区名称”和“首都/城市”,并在垂直方向用花括号括起来: def json_countries_and_capitals(): """ This function prints each country and its capital in json format. """ output = [{'country_name': i[0], 'capital_city':i[1]} for i i

我需要打印“国家/地区名称”和“首都/城市”,并在垂直方向用花括号括起来:

def json_countries_and_capitals():
    """
    This function prints each country and its capital in json format.
    """
output = [{'country_name': i[0], 'capital_city':i[1]} for i in countries_and_capitals]
我试过这个,但它没有用花括号打印出来,但它确实打印出了我需要它的方式

countries_plus_capitals = json.dumps(countries_and_capitals, indent=4)
while countries_plus_capitals:
    print(output)
    print(countries_plus_capitals)
    break
[{'国家名称':'阿富汗','首都城市':'喀布尔'},等等

I need it to print like this vertically:
[ { “国家名称”:“阿富汗”, “首都”:“喀布尔” }, { “国家名称”:“阿尔巴尼亚”, “首都”:“地拉那(地拉那)” }, { “国家名称”:“阿尔及利亚”, “首都”:“阿尔及尔” }, ……等等… { “国家名称”:“津巴布韦”, “首都”:“哈拉雷” } ]


只需迭代列表并创建字典

l=[“阿富汗”、“喀布尔”]、[“阿尔巴尼亚”、“地拉那(地拉那)”、[“阿尔及利亚”、“阿尔及尔”]、[“安道尔”、“安道尔·拉维拉”]、[“安哥拉”、“罗安达”]、[“安提瓜和巴布达”、“圣约翰”]、[“阿根廷”、“布宜诺斯艾利斯”]、[“亚美尼亚”、“埃里温”]、[“澳大利亚”、“堪培拉”、[“奥地利”、“维也纳”]、[“阿塞拜疆”、“巴库”]、[“巴哈马”、“拿骚”、“巴林”、“麦纳麦”、“孟加拉国”、“达卡”、“巴巴多斯”、“布里奇敦”、“白俄罗斯”、“明斯克”、“比利时”、“布鲁塞尔”、“伯利兹”、“贝尔莫潘”、“贝宁”、“新波尔图”、“不丹”、“廷布”、“玻利维亚”、“苏克雷”、“波斯尼亚和黑塞哥维那”、“萨拉热窝”、“博茨瓦纳”、“哈博罗内”、“巴西”、“巴西利亚”“]、[“文莱”、“斯里巴加湾班达尔”、“保加利亚”、“索非亚”、“布基纳法索”、“瓦加杜古”、“布隆迪”、“吉特加”、“柬埔寨”、“金边”、“喀麦隆”、“雅温得”、“加拿大”、“渥太华”、“佛得角”、“普拉亚”、“中非共和国”、“班吉”、“乍得”、“恩贾梅纳”、“智利”、“圣地亚哥”、“中国”、“北京”],[“哥伦比亚”、“波哥大”]、[“科摩罗”、“摩罗尼”]、[“刚果民主共和国”、“金沙萨”]、[“刚果共和国”、“布拉柴维尔”]、[“哥斯达黎加”、“圣何塞”]、[“科特迪瓦(科特迪瓦)”、“亚穆苏克罗”]、[“克罗地亚”、“萨格勒布”]、[“古巴”、“哈瓦那”]、[“塞浦路斯”、“尼科西亚”]、[“捷克共和国(捷克)”、“布拉格”]、[“丹麦”、“哥本哈根”、“吉布提”、“吉布提”、“多米尼加”、“罗索”、“多米尼加共和国”、“圣多明各”、“东帝汶”、“帝力”、“厄瓜多尔”、“基多”、“埃及”、“开罗”、“萨尔瓦多”、“圣萨尔瓦多”、“英格兰”、“伦敦”、“赤道几内亚”、“马拉博”、“厄立特里亚”、“阿斯马拉”、“爱沙尼亚”、“塔林”、“西班牙”埃斯瓦蒂尼(斯威士兰)、“姆巴巴纳”、“埃塞俄比亚”、“亚的斯亚贝巴”、“密克罗尼西亚联邦”、“帕利基尔”、“斐济”、“苏瓦”、“芬兰”、“赫尔辛基”、“法国”、“巴黎”、“加蓬”、“利伯维尔”、“冈比亚”、“班珠尔”、“格鲁吉亚”、“第比利斯”、“德国”、“柏林”、“加纳”、“阿克拉”、“希腊”、“雅典”、“格林纳达”、“格林纳达”圣乔治、危地马拉、危地马拉城、几内亚、科纳克里、几内亚比绍、圭亚那、乔治敦、海地、太子港、洪都拉斯、特古西加尔巴、匈牙利、布达佩斯、冰岛、雷克雅未克、印度、新德里、印度尼西亚、雅加达、伊朗、德黑兰、伊拉克、巴格达“]、[“爱尔兰”、“都柏林”]、[“以色列”、“耶路撒冷”]、[“意大利”、“罗马”]、[“牙买加”、“金斯敦”]、[“日本”、“东京”]、[“约旦”、“安曼”]、[“哈萨克斯坦”、“努尔苏丹”]、[“肯尼亚”、“内罗毕”]、[“基里巴斯”、“塔拉瓦环礁”]、[“科索沃”、“普里什蒂纳”]、[“科威特城”]、[“吉尔吉斯斯坦”、“比什凯克”]、[“老挝”、“万象”]、[“拉脱维亚”、“里加”、“黎巴嫩”、“贝鲁特”、“莱索托”、“马塞卢”、“利比里亚”、“蒙罗维亚”、“利比亚”、“的黎波里”、“列支敦士登”、“瓦杜兹”、“立陶宛”、“维尔纽斯”、“卢森堡”、“马达加斯加”、“安塔那那利佛”、“马拉维”、“利隆圭”、“马来西亚”、“吉隆坡”、“马尔代夫”、“男性”、“马里”、“巴马科”,[“马耳他”、“瓦莱塔”]、[“马绍尔群岛”、“马朱罗”]、[“毛里塔尼亚”、“努瓦克肖特”]、[“毛里求斯”、“路易港”]、[“墨西哥”、“墨西哥城”]、[“摩尔多瓦”、“基希讷乌”]、[“摩纳哥”、“摩纳哥”]、[“蒙古”、“乌兰巴托”]、[“黑山”、“波德戈里察”]、[“摩洛哥”、“拉巴特”]、[“莫桑比克”、“马普托”]、[“缅甸”、“内比都”“]、[“纳米比亚”、“温得和克”]、[“瑙鲁”、“无官方首都”]、[“尼泊尔”、“加德满都”]、[“荷兰”、“阿姆斯特丹”]、[“新西兰”、“惠灵顿”]、[“尼加拉瓜”、“马那瓜”]、[“尼日尔”、“尼亚美”]、[“尼日利亚”、“阿布贾”]、[“朝鲜”、“平壤”]、[“北马其顿(马其顿)”、“斯科普里”]、[“北爱尔兰”、“贝尔法斯特”]、[“挪威”、“奥斯陆”、“阿曼”、“马斯喀特”、“巴基斯坦”、“伊斯兰堡”、“帕劳”、“梅勒切克”、“巴拿马”、“巴拿马城”、“巴布亚新几内亚”、“莫尔斯比港”、“巴拉圭”、“亚松森”、“秘鲁”、“利马”、“菲律宾”、“马尼拉”、“波兰”、“华沙”、“葡萄牙”、“里斯本”、“卡塔尔”、“多哈”、“罗马尼亚”、“布加勒斯特”、“西班牙”俄罗斯、莫斯科、卢旺达、基加利、圣基茨和尼维斯、巴塞特雷、圣卢西亚、卡斯特里、圣文森特和格林纳丁斯、金斯敦、萨摩亚、阿皮亚、圣马力诺、圣多美和普林西比、沙特阿拉伯、利雅得、苏格兰、爱丁堡、塞内加尔、达喀尔、,[“塞尔维亚”、“贝尔格莱德”、“塞舌尔”、“维多利亚”、“塞拉利昂”、“弗里敦”、“新加坡”、“新加坡”、“斯洛伐克”、“布拉迪斯拉发”、“斯洛文尼亚”、“卢布尔雅那”、“所罗门群岛”、“霍尼亚拉”、“索马里”、“摩加迪沙”、“南非”、“比勒陀利亚、布隆方丹、开普敦”、“韩国”、“首尔”、“南苏丹”、“朱巴”],[“西班牙”、“马德里”]、[“斯里兰卡”、“科伦坡”]、[“苏丹”、“喀土穆”]、[“苏里南”、“帕拉马里博”]、[“瑞典”、“斯德哥尔摩”]、[“瑞士”、“伯尔尼”]、[“叙利亚”、“大马士革”]、[“台湾”、“台北”]、[“塔吉克斯坦”、“杜尚别”]、[“坦桑尼亚”、“多多马”]、[“泰国”、“曼谷”、[“多哥”、“洛美”]、[“汤加”、“努库阿洛法”]、[”特立尼达和多巴哥、西班牙港、[“突尼斯”、“突尼斯”]、[“图
I need it to print like this vertically:
[{'country_name': 'Afghanistan', 'capital_city': 'Kabul'},
 {'country_name': 'Albania', 'capital_city': 'Tirana (Tirane)'},
 {'country_name': 'Algeria', 'capital_city': 'Algiers'},
 {'country_name': 'Andorra', 'capital_city': 'Andorra la Vella'},
 {'country_name': 'Angola', 'capital_city': 'Luanda'},
 {'country_name': 'Antigua and Barbuda', 'capital_city': "Saint John's"},
 {'country_name': 'Argentina', 'capital_city': 'Buenos Aires'},
 {'country_name': 'Armenia', 'capital_city': 'Yerevan'},
 {'country_name': 'Australia', 'capital_city': 'Canberra'},
 {'country_name': 'Austria', 'capital_city': 'Vienna'},
 {'country_name': 'Azerbaijan', 'capital_city': 'Baku'},
 {'country_name': 'Bahamas', 'capital_city': 'Nassau'},
 {'country_name': 'Bahrain', 'capital_city': 'Manama'},
 {'country_name': 'Bangladesh', 'capital_city': 'Dhaka'},
 {'country_name': 'Barbados', 'capital_city': 'Bridgetown'},
 {'country_name': 'Belarus', 'capital_city': 'Minsk'},
 {'country_name': 'Belgium', 'capital_city': 'Brussels'},
 {'country_name': 'Belize', 'capital_city': 'Belmopan'},
 {'country_name': 'Benin', 'capital_city': 'Porto Novo'},
 {'country_name': 'Bhutan', 'capital_city': 'Thimphu'},
 {'country_name': 'Bolivia', 'capital_city': 'Sucre'},
 {'country_name': 'Bosnia and Herzegovina', 'capital_city': 'Sarajevo'},
 {'country_name': 'Botswana', 'capital_city': 'Gaborone'},
 {'country_name': 'Brazil', 'capital_city': 'Brasilia'},
 {'country_name': 'Brunei', 'capital_city': 'Bandar Seri Begawan'},
 {'country_name': 'Bulgaria', 'capital_city': 'Sofia'},
 {'country_name': 'Burkina Faso', 'capital_city': 'Ouagadougou'},
 {'country_name': 'Burundi', 'capital_city': 'Gitega'},
 {'country_name': 'Cambodia', 'capital_city': 'Phnom Penh'},
 {'country_name': 'Cameroon', 'capital_city': 'Yaounde'},
 {'country_name': 'Canada', 'capital_city': 'Ottawa'},
 {'country_name': 'Cape Verde', 'capital_city': 'Praia'},
 {'country_name': 'Central African Republic', 'capital_city': 'Bangui'},
 {'country_name': 'Chad', 'capital_city': "N'Djamena"},
 {'country_name': 'Chile', 'capital_city': 'Santiago'},
 {'country_name': 'China', 'capital_city': 'Beijing'},
 {'country_name': 'Colombia', 'capital_city': 'Bogota'},
 {'country_name': 'Comoros', 'capital_city': 'Moroni'},
 {'country_name': 'Congo, Democratic Republic of the',
  'capital_city': 'Kinshasa'},
 {'country_name': 'Congo, Republic of the', 'capital_city': 'Brazzaville'},
 {'country_name': 'Costa Rica', 'capital_city': 'San Jose'},
 {'country_name': "Cote d'Ivoire (Ivory Coast)",
  'capital_city': 'Yamoussoukro'},
 {'country_name': 'Croatia', 'capital_city': 'Zagreb'},
 {'country_name': 'Cuba', 'capital_city': 'Havana'},
 {'country_name': 'Cyprus', 'capital_city': 'Nicosia'},
 {'country_name': 'Czech Republic (Czechia)', 'capital_city': 'Prague'},
 {'country_name': 'Denmark', 'capital_city': 'Copenhagen'},
 {'country_name': 'Djibouti', 'capital_city': 'Djibouti'},
 {'country_name': 'Dominica', 'capital_city': 'Roseau'},
 {'country_name': 'Dominican Republic', 'capital_city': 'Santo Domingo'},
 {'country_name': 'East Timor', 'capital_city': 'Dili'},
 {'country_name': 'Ecuador', 'capital_city': 'Quito'},
 {'country_name': 'Egypt', 'capital_city': 'Cairo'},
 {'country_name': 'El Salvador', 'capital_city': 'San Salvador'},
 {'country_name': 'England', 'capital_city': 'London'},
 {'country_name': 'Equatorial Guinea', 'capital_city': 'Malabo'},
 {'country_name': 'Eritrea', 'capital_city': 'Asmara'},
 {'country_name': 'Estonia', 'capital_city': 'Tallinn'},
 {'country_name': 'Eswatini (Swaziland)', 'capital_city': 'Mbabana'},
 {'country_name': 'Ethiopia', 'capital_city': 'Addis Ababa'},
 {'country_name': 'Federated States of Micronesia', 'capital_city': 'Palikir'},
 {'country_name': 'Fiji', 'capital_city': 'Suva'},
 {'country_name': 'Finland', 'capital_city': 'Helsinki'},
 {'country_name': 'France', 'capital_city': 'Paris'},
 {'country_name': 'Gabon', 'capital_city': 'Libreville'},
 {'country_name': 'Gambia', 'capital_city': 'Banjul'},
 {'country_name': 'Georgia', 'capital_city': 'Tbilisi'},
 {'country_name': 'Germany', 'capital_city': 'Berlin'},
 {'country_name': 'Ghana', 'capital_city': 'Accra'},
 {'country_name': 'Greece', 'capital_city': 'Athens'},
 {'country_name': 'Grenada', 'capital_city': "Saint George's"},
 {'country_name': 'Guatemala', 'capital_city': 'Guatemala City'},
 {'country_name': 'Guinea', 'capital_city': 'Conakry'},
 {'country_name': 'Guinea-Bissau', 'capital_city': 'Bissau'},
 {'country_name': 'Guyana', 'capital_city': 'Georgetown'},
 {'country_name': 'Haiti', 'capital_city': 'Port au Prince'},
 {'country_name': 'Honduras', 'capital_city': 'Tegucigalpa'},
 {'country_name': 'Hungary', 'capital_city': 'Budapest'},
 {'country_name': 'Iceland', 'capital_city': 'Reykjavik'},
 {'country_name': 'India', 'capital_city': 'New Delhi'},
 {'country_name': 'Indonesia', 'capital_city': 'Jakarta'},
 {'country_name': 'Iran', 'capital_city': 'Tehran'},
 {'country_name': 'Iraq', 'capital_city': 'Baghdad'},
 {'country_name': 'Ireland', 'capital_city': 'Dublin'},
 {'country_name': 'Israel', 'capital_city': 'Jerusalem'},
 {'country_name': 'Italy', 'capital_city': 'Rome'},
 {'country_name': 'Jamaica', 'capital_city': 'Kingston'},
 {'country_name': 'Japan', 'capital_city': 'Tokyo'},
 {'country_name': 'Jordan', 'capital_city': 'Amman'},
 {'country_name': 'Kazakhstan', 'capital_city': 'Nur-Sultan'},
 {'country_name': 'Kenya', 'capital_city': 'Nairobi'},
 {'country_name': 'Kiribati', 'capital_city': 'Tarawa Atoll'},
 {'country_name': 'Kosovo', 'capital_city': 'Pristina'},
 {'country_name': 'Kuwait', 'capital_city': 'Kuwait City'},
 {'country_name': 'Kyrgyzstan', 'capital_city': 'Bishkek'},
 {'country_name': 'Laos', 'capital_city': 'Vientiane'},
 {'country_name': 'Latvia', 'capital_city': 'Riga'},
 {'country_name': 'Lebanon', 'capital_city': 'Beirut'},
 {'country_name': 'Lesotho', 'capital_city': 'Maseru'},
 {'country_name': 'Liberia', 'capital_city': 'Monrovia'},
 {'country_name': 'Libya', 'capital_city': 'Tripoli'},
 {'country_name': 'Liechtenstein', 'capital_city': 'Vaduz'},
 {'country_name': 'Lithuania', 'capital_city': 'Vilnius'},
 {'country_name': 'Luxembourg', 'capital_city': 'Luxembourg'},
 {'country_name': 'Madagascar', 'capital_city': 'Antananarivo'},
 {'country_name': 'Malawi', 'capital_city': 'Lilongwe'},
 {'country_name': 'Malaysia', 'capital_city': 'Kuala Lumpur'},
 {'country_name': 'Maldives', 'capital_city': 'Male'},
 {'country_name': 'Mali', 'capital_city': 'Bamako'},
 {'country_name': 'Malta', 'capital_city': 'Valletta'},
 {'country_name': 'Marshall Islands', 'capital_city': 'Majuro'},
 {'country_name': 'Mauritania', 'capital_city': 'Nouakchott'},
 {'country_name': 'Mauritius', 'capital_city': 'Port Louis'},
 {'country_name': 'Mexico', 'capital_city': 'Mexico City'},
 {'country_name': 'Moldova', 'capital_city': 'Chisinau'},
 {'country_name': 'Monaco', 'capital_city': 'Monaco'},
 {'country_name': 'Mongolia', 'capital_city': 'Ulaanbaatar'},
 {'country_name': 'Montenegro', 'capital_city': 'Podgorica'},
 {'country_name': 'Morocco', 'capital_city': 'Rabat'},
 {'country_name': 'Mozambique', 'capital_city': 'Maputo'},
 {'country_name': 'Myanmar (Burma)', 'capital_city': 'Nay Pyi Taw'},
 {'country_name': 'Namibia', 'capital_city': 'Windhoek'},
 {'country_name': 'Nauru', 'capital_city': 'No official capital'},
 {'country_name': 'Nepal', 'capital_city': 'Kathmandu'},
 {'country_name': 'Netherlands', 'capital_city': 'Amsterdam'},
 {'country_name': 'New Zealand', 'capital_city': 'Wellington'},
 {'country_name': 'Nicaragua', 'capital_city': 'Managua'},
 {'country_name': 'Niger', 'capital_city': 'Niamey'},
 {'country_name': 'Nigeria', 'capital_city': 'Abuja'},
 {'country_name': 'North Korea', 'capital_city': 'Pyongyang'},
 {'country_name': 'North Macedonia (Macedonia)', 'capital_city': 'Skopje'},
 {'country_name': 'Northern Ireland', 'capital_city': 'Belfast'},
 {'country_name': 'Norway', 'capital_city': 'Oslo'},
 {'country_name': 'Oman', 'capital_city': 'Muscat'},
 {'country_name': 'Pakistan', 'capital_city': 'Islamabad'},
 {'country_name': 'Palau', 'capital_city': 'Melekeok'},
 {'country_name': 'Panama', 'capital_city': 'Panama City'},
 {'country_name': 'Papua New Guinea', 'capital_city': 'Port Moresby'},
 {'country_name': 'Paraguay', 'capital_city': 'Asuncion'},
 {'country_name': 'Peru', 'capital_city': 'Lima'},
 {'country_name': 'Philippines', 'capital_city': 'Manila'},
 {'country_name': 'Poland', 'capital_city': 'Warsaw'},
 {'country_name': 'Portugal', 'capital_city': 'Lisbon'},
 {'country_name': 'Qatar', 'capital_city': 'Doha'},
 {'country_name': 'Romania', 'capital_city': 'Bucharest'},
 {'country_name': 'Russia', 'capital_city': 'Moscow'},
 {'country_name': 'Rwanda', 'capital_city': 'Kigali'},
 {'country_name': 'Saint Kitts and Nevis', 'capital_city': 'Basseterre'},
 {'country_name': 'Saint Lucia', 'capital_city': 'Castries'},
 {'country_name': 'Saint Vincent and the Grenadines',
  'capital_city': 'Kingstown'},
 {'country_name': 'Samoa', 'capital_city': 'Apia'},
 {'country_name': 'San Marino', 'capital_city': 'San Marino'},
 {'country_name': 'Sao Tome and Principe', 'capital_city': 'Sao Tome'},
 {'country_name': 'Saudi Arabia', 'capital_city': 'Riyadh'},
 {'country_name': 'Scotland', 'capital_city': 'Edinburgh'},
 {'country_name': 'Senegal', 'capital_city': 'Dakar'},
 {'country_name': 'Serbia', 'capital_city': 'Belgrade'},
 {'country_name': 'Seychelles', 'capital_city': 'Victoria'},
 {'country_name': 'Sierra Leone', 'capital_city': 'Freetown'},
 {'country_name': 'Singapore', 'capital_city': 'Singapore'},
 {'country_name': 'Slovakia', 'capital_city': 'Bratislava'},
 {'country_name': 'Slovenia', 'capital_city': 'Ljubljana'},
 {'country_name': 'Solomon Islands', 'capital_city': 'Honiara'},
 {'country_name': 'Somalia', 'capital_city': 'Mogadishu'},
 {'country_name': 'South Africa',
  'capital_city': 'Pretoria, Bloemfontein, Cape Town'},
 {'country_name': 'South Korea', 'capital_city': 'Seoul'},
 {'country_name': 'South Sudan', 'capital_city': 'Juba'},
 {'country_name': 'Spain', 'capital_city': 'Madrid'},
 {'country_name': 'Sri Lanka', 'capital_city': 'Colombo'},
 {'country_name': 'Sudan', 'capital_city': 'Khartoum'},
 {'country_name': 'Suriname', 'capital_city': 'Paramaribo'},
 {'country_name': 'Sweden', 'capital_city': 'Stockholm'},
 {'country_name': 'Switzerland', 'capital_city': 'Bern'},
 {'country_name': 'Syria', 'capital_city': 'Damascus'},
 {'country_name': 'Taiwan', 'capital_city': 'Taipei'},
 {'country_name': 'Tajikistan', 'capital_city': 'Dushanbe'},
 {'country_name': 'Tanzania', 'capital_city': 'Dodoma'},
 {'country_name': 'Thailand', 'capital_city': 'Bangkok'},
 {'country_name': 'Togo', 'capital_city': 'Lome'},
 {'country_name': 'Tonga', 'capital_city': "Nuku'alofa"},
 {'country_name': 'Trinidad and Tobago', 'capital_city': 'Port of Spain'},
 {'country_name': 'Tunisia', 'capital_city': 'Tunis'},
 {'country_name': 'Turkey', 'capital_city': 'Ankara'},
 {'country_name': 'Turkmenistan', 'capital_city': 'Ashgabat'},
 {'country_name': 'Tuvalu', 'capital_city': 'Funafuti'},
 {'country_name': 'Uganda', 'capital_city': 'Kampala'},
 {'country_name': 'Ukraine', 'capital_city': 'Kiev'},
 {'country_name': 'United Arab Emirates', 'capital_city': 'Abu Dhabi'},
 {'country_name': 'United Kingdom', 'capital_city': 'London'},
 {'country_name': 'United States', 'capital_city': 'Washington D.C.'},
 {'country_name': 'Uruguay', 'capital_city': 'Montevideo'},
 {'country_name': 'Uzbekistan', 'capital_city': 'Tashkent'},
 {'country_name': 'Vanuatu', 'capital_city': 'Port Vila'},
 {'country_name': 'Vatican City', 'capital_city': 'Vatican City'},
 {'country_name': 'Venezuela', 'capital_city': 'Caracas'},
 {'country_name': 'Vietnam', 'capital_city': 'Hanoi'},
 {'country_name': 'Wales', 'capital_city': 'Cardiff'},
 {'country_name': 'Yemen', 'capital_city': "Sana'a"},
 {'country_name': 'Zambia', 'capital_city': 'Lusaka'},
 {'country_name': 'Zimbabwe', 'capital_city': 'Harare'}]
output = [{'country_name': i[0], 'capital_city':i[1]} for i in countries_and_capitals]
countries_plus_capitals = json.dumps(output, indent=4)
while countries_plus_capitals:
    print(countries_plus_capitals)
    break