How would the function know which list to use in the default case getStats()
? Assuming your function works exactly the same with countries and regions and you want to supply defaults for both, then make them lists outside the function that a user can apply. As mentioned, the parameter name can be more vague getStats(location)
and require a list, but the user has handy default ones available.
countries = ['France','Spain','Italy','US']
regions = ['New York','Boston','San Francisco'])
def getStats(location):
"""Get stats for location. Default `countries` and `regions` lists
available."""
....
Or, if you prefer, define multiple functions that call the common one.
def getStatsByCountry(countries=['France','Spain','Italy','US']):
return getStats(countries)
def getStatsByRegion(regions=['New York','Boston','San Francisco']):
return getStats(regions)