Answers for "Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_')."

0

Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').

def solution(s):
    list_of_pairs = []
    pair = ''
    for char in s:
        pair += char
        if len(pair) == 2:
            list_of_pairs.append(pair)
            pair = ''
    if pair:
        list_of_pairs.append(pair + '_')
    return list_of_pairs
Posted by: Guest on October-04-2021

Code answers related to "Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_')."

Code answers related to "Javascript"

Browse Popular Code Answers by Language