Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Adapt input string solution in Creative category for Split Pairs by frankiser
def split_pairs(a):
"""
Returns an iterable of pairs of two characters.
First we ensure the input string has an even amount of characters.
"""
if len(a)%2 != 0:
newString = a + '_'
else:
newString = a
pair: list[str] = []
for index in range(0,len(newString),2):
pair.append(newString[index] + newString[index+1])
return pair
if __name__ == '__main__':
print("Example:")
print(list(split_pairs('abcd')))
# These "asserts" are used for self-checking and not for an auto-testing
assert list(split_pairs('abcd')) == ['ab', 'cd']
assert list(split_pairs('abc')) == ['ab', 'c_']
assert list(split_pairs('abcdf')) == ['ab', 'cd', 'f_']
assert list(split_pairs('a')) == ['a_']
assert list(split_pairs('')) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
May 1, 2020
Comments: