Cody Bable

Generation

generate functionFri, 19 May 2023

Split the string into pairs of two characters. If the string contains an odd number of characters, then the missing second character of the final pair should be replaced with an underscore ('_'). def split_pairs(text: str) -> Iterable[str]:

def split_pairs(text: str) -> Iterable[str]: if len(text) % 2 != 0: text += '_' lst = [text[i:i+2] for i in range(0, len(text), 2)] return lst

Questions about programming?Chat with your personal AI assistant