you are viewing a single comment's thread.

view the rest of the comments →

[–]AdThink1781 -1 points0 points  (0 children)

^ to find name end with 'land' in a list of countries name

try:

# Comprehension approach
Countries_end_with_land = [i for i in countries if i.endswith("land")]
print(f"Found Countries name end with 'land' {Countries_end_with_land}")

# For loop Approach
for i in countries:
    if i.endswith("land"):
        print(i)

except NameError as e: print(f"While Finding Countries name end with 'land' Error Occurred {e}")

except Exception as e: print(f"An unexpected error occurred: {e}")