Вероятно, самым простым способом было бы использовать список, а содержит функцию .
# I put all the names in this list.
list_of_names = ['New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Rhode Island', 'South Carolina', 'South Dakota', 'West Virginia', 'new hampshire', 'new jersey', 'new mexico', 'new york', 'north carolina', 'north dakota', 'rhode island', 'south carolina', 'south dakota', 'west Virginia', 'Alexander City', 'Fort Payne', 'Phenix City', 'Casa Grande', 'Gila Bend', 'Havasu City', 'Sierra Vista', 'Window Rock', 'Arkansas Post', 'El Dorado', 'Forrest City', 'Fort Smith', 'Hot Springs', 'Little Rock', 'Little Rock', 'Pine Bluff', 'Van Buren', 'West Memphis', 'Beverly Hills', 'Buena Park', 'Chula Vista', 'Costa Mesa', 'Culver City', 'Daly City', 'El Centro', 'El Cerrito', 'El Monte', 'Garden Grove', 'Huntington Beach', 'La Habra', 'Laguna Beach', 'Long Beach', 'Los Angeles', 'Menlo Park', 'Mountain View', 'Newport Beach', 'Pacific Grove', 'Palm Springs', 'Palo Alto', 'Port Hueneme', 'Rancho Cucamonga', 'Red Bluff', 'Redondo Beach', 'Redwood City', 'San Bernardino', 'San Clemente', 'San Diego', 'San Fernando', 'San Francisco', 'San Gabriel', 'San Jose', 'Juan Capistrano', 'San Leandro', 'Luis Obispo', 'San Marino', 'San Mateo', 'San Pedro', 'San Rafael', 'San Simeon', 'Santa Ana', 'Santa Barbara', 'Santa Clara', 'Santa Clarita', 'Santa Cruz', 'Santa Monica', 'Santa Rosa', 'Simi Valley', 'San Francisco', 'Thousand Oaks', 'Walnut Creek', 'West Covina', 'Yorba Linda', 'Yuba City', 'Canon City', 'Central City', 'Colorado Springs', 'Cripple Creek', 'Estes Park', 'Fort Collins', 'Fort Morgan', 'Glenwood Springs', 'Grand Junction', 'La Junta', 'Pagosa Springs', 'Steamboat Springs', 'East Hartford', 'East Haven', 'New Britain', 'New Haven', 'New London', 'North Haven', 'Old Saybrook', 'West Hartford', 'West Haven', 'Windsor Locks', 'New Castle', 'Belle Glade', 'Boca Raton', 'Cape Coral', 'Cocoa Beach', 'Coral Gables', 'Daytona Beach', 'De Land', 'Deerfield Beach', 'Delray Beach', 'Fernandina Beach', 'Fort Lauderdale', 'Fort Myers', 'Fort Pierce', 'Walton Beach', 'Hallandale Beach', 'Key West', 'Lake City', 'Lake Wales', 'Miami Beach', 'Smyrna Beach', 'Ormond Beach', 'Palm Bay', 'Palm Beach', 'Panama City', 'Pompano Beach', 'Saint Augustine', 'Saint Petersburg', 'Tarpon Springs', 'Palm Beach', 'White Springs', 'Winter Haven', 'Winter Park', 'East Point', 'Fort Valley', 'La Grange', 'Warm Springs', 'Warner Robins', 'Bonners Ferry', 'Idaho City', 'Idaho Falls', 'Priest River', 'Sun Valley', 'Twin Falls', 'Arlington Heights', 'Calumet City', 'Chicago Heights', 'Des Plaines', 'East Moline', 'Saint Louis', 'Glen Ellyn', 'Granite City', 'Highland Park', 'La Salle', 'Lake Forest', 'Mount Vernon', 'North Chicago', 'Oak Park', 'Park Forest', 'Park Ridge', 'River Forest', 'Rock Island', 'South Holland', 'Wood River', 'East Chicago', 'Fort Wayne', 'French Lick', 'Michigan City', 'New Albany', 'New Castle', 'New Harmony', 'Santa Claus', 'South Bend', 'Terre Haute', 'West Lafayette', 'Amana Colonies', 'Cedar Falls', 'Cedar Rapids', 'Charles City', 'Council Bluffs', 'Des Moines', 'Fort Dodge', 'Iowa City', 'Mason City', 'Mount Pleasant', 'Sioux City', 'Webster City', 'Des Moines', 'Arkansas City', 'Council Grove', 'Dodge City', 'Fort Scott', 'Garden City', 'Great Bend', 'Junction City', 'Kansas City', 'Medicine Lodge', 'Overland Park', 'Smith Center', 'Bowling Green']
def is_allowed_location(location): # I'm guessing we're supposed to put a name, as a str, for location.
# Check to see it location is in the list.
if list_of_names.__contains__(location):
# If location is one of the cities, return the name as a str. If it's not in the list, return None.
return location # OR you could just return list_of_names.__contains__(location) without the if statement to return a boolean.
print(is_allowed_location("New Mexico")) # Test. --> "New Mexico"
print(is_allowed_location("Mayberry")) # Test. --> None