I'm learning Python and trying to solve the same problem ("Friend or Foe?"). I wrote the code below and would like to find out how to move-on following "my logic" way.
It seems that it adds just the very first item to the new_friends list but doesn't iterate over all the elements of x list.
Beside above, the return value is None ... what am I not noticing here?
def friend(x):
x = ["Ryan", "Kieran", "Jason", "Yous"]
new_friends = []
for str in x:
if len(str) == 4:
return new_friends.append(str)
return new_friends[0:]
Instead of if statement I also tried a nested while loop .. but no success adding other items to the new_friends list.