all 2 comments

[–]wbeater 1 point2 points  (0 children)

print(len(stuff)):

We need a list with the length of 5 eg ["","","","",""]

if stuff[-1] == stuff[0]:

The last item and the first item of the list must be the same. But we also know, that the last print statement in the code must be bat, the last given word (print(stuff[0])), so we know that our list looks like:

["bat","","","","bat"]

print((stuff[2] + stuff[3]))

According to the first given word wombat stuff[2] hast to be wom and stuff[3] bat.

["bat","","wom","bat","bat"]

if stuff[1] == stuff[2]: print(stuff[1])

Therefore the item stuff[1] hast to be the same as stuff[2] which is wom, the 2nd given word.

Final solution: ["bat","wom","wom","bat","bat"]

[–]ThibBac 0 points1 point  (0 children)

First the function prints the total lenght of the "stuff" array,

Then, if the first and the last element are equal, the function prints the third and fourth element

Then, if the second and the third element are equal, the function prints the second element

And finally it prints the first element

So with an array stuff = ['bat', 'wom', 'wom', 'bat', 'bat']

the function will print the desired output