👋 Hey there, I am Waylon Walker
I am a Husband, Father of two beautiful children, Senior Python Developer currently working in the Data Engineering platform space. I am a continuous learner, and sha
You can also get the index in a more pythonic fashion by using the enumerate function to get the index while looping. This version, uses enumerate and f-strings.
# Un-nested for loops
defprint_letters_from_countries(countries):fori,countryinenumerate(countries):#iterate over countries list
print('beginning of outer loop')print(f'{country} is at index {i} of {countries}\n')print(f'beginning of inner loop for {country}')print_letters_from_country(country)defprint_letters_from_country(country):fori,letterinenumerate(country):#iterate over each country in countries list
print(f'{letter} is at index {i} of {country}')print(f'end of inner loop for {country}\n')countries=['Germany','USA','Spain']print_letters_from_countries(countries)
You can also get the index in a more pythonic fashion by using the enumerate function to get the index while looping. This version, uses enumerate and f-strings.
nice update!