Sharing Solutions

I see, thank you ionatan

Here what I started with:

def make_spoonerism(word1,word2):
  letter1 = word1[0]
  letter2 = word2[0]
  new_word1 = letter2 + word1[1:]
  new_word2 = letter1 + word2[1:]
  new_phrase = new_word1 + ' ' + new_word2
  return new_phrase

Here’s what I whittled it down to:

def make_spoonerism(word1,word2):
  return f'{word2[0]}{word1[1:]} {word1[0]}{word2[1:]}'

Similar to a few others but f-strings are my jam!

1 Like

Solution replacing letters
I hope it`s easy to understand

def make_spoonerism(word1,word2):
#Replace the first letter of a word with the first letter of the other word
  w1 = word1.replace(word1[0], word2[0])
  w2 = word2.replace(word2[0], word1[0])

  return w1 + ' ' + w2

Can you explain how the simplified version works?

I made use of slicing to replace the first character of each word and used string concatenation to get the result.

def make_spoonerism(word1, word2):
return word2[0:1] + word1[1:] + ’ ’ + word1[0:1] + word2[1:]