samedi 28 mars 2015

How to mix strings in Python

I am trying to write a function to mix strings in python but I am getting stuck at the end. So for this example, I have 2 words, mix and pod. I would like to create a function that returns: pox mid


My code only returns pox mix


Code:



def mix_up(a, b):
if len(a and b)>1:
b=str.replace(b,b[2],a[2:3])
a=str.replace(a,a[2],b[2])
print b,"",a
return
mix_up('mix','pod')


Thanks!


Aucun commentaire:

Enregistrer un commentaire