Я использую библиотеку стран python и хочу перечислить и распечатать все штаты и города данной страны, используя python, возможно ли это сделать?
def Contries(request):
for country in pycountry.countries:
list.append(country.name)
if list:
return JsonResponse(
{"code": status.HTTP_200_OK, "success": True, "response": list},
status=status.HTTP_200_OK)
else:
return JsonResponse(
{"code": status.HTTP_400_BAD_REQUEST, "success": False, "response":"list"},
status=status.HTTP_400_BAD_REQUEST)
Есть ли возможность получить список городов и штатов заданной страны с помощью python
Вот пример использования pycountry:
import pycountry
def cities_in_country(country):
list_ = []
for region in pycountry.subdivisions.get(country_code=country):
list_.append(region.name)
return list_
print(cities_in_country("FR"))