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. If the letters 'ь', 'ъ', 'ы' are the last ones, then the next letter from the end is taken. Display YES if the sequence matches this rule and NO otherwise.

def func(data): last_letter = data[0][-1] for item in data[1:]: if last_letter == 'ы': last_letter = data[-2] elif last_letter == 'ь' or last_letter == 'ъ': last_letter = data[-3] elif item.startswith(last_letter): last_letter = item[-1] continue else: return 'NO' return 'YES'

Questions about programming?Chat with your personal AI assistant