lundi 17 août 2020

Split word in two pairs but with little change

i need help with given task -

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 ('_').

And my code is:

def split_pairs(a):
if len(a)%2==0:
    a.split(', ', 2)
else:
    a.split(', ', 2)
    a.replace(items[2][-1] , '_')
    return a

Aucun commentaire:

Enregistrer un commentaire