generate functionFri, 10 Mar 2023

a list of city names is given in one line separated by a space. Iterate through all these names with a for loop and determine if the name of the next city begins with the last letter of the previous city in the list. Display YES if the sequence matches this rule and NO otherwise.

def city_match(string): string = string.split(' ') for i in range(len(string)-1): if string[i][-1] == string[i+1][0]: print('YES') else: print('NO') city_match('London Berlin Madrid Moscow')

Questions about programming?Chat with your personal AI assistant