May-23-2020, 03:30 PM
This should help. I simplified the code some, set your country limit to an arbitrarily high number (one would hope there will never be 100,000 countries), limit works,
I am not sure what you want for the second part. The function returns a list object. You can assign that list to another name, copy the list, do whatever you like. Can you clarify what you wanted for the second part?
I am not sure what you want for the second part. The function returns a list object. You can assign that list to another name, copy the list, do whatever you like. Can you clarify what you wanted for the second part?
import urllib import json def list_of_countries(number_to_return=100000): allurl='https://restcountries.eu/rest/v2/all' uh=urllib.request.urlopen(allurl) data = uh.read().decode() z=json.loads(data) lim=number_to_return country_list=list() for country in z : country_list.append(country['name']) lim -= 1 if lim == 0: break return country_list print(list_of_countries())