Saturday, January 29, 2022

Friend or foe CodeWars Python

 

def friend(x):
    friend_list = []
    for word in x:
        if len(word) == 4:
            friend_list.append(word)
    return friend_list

Using list comprehension:

 

def friend(x):     
    return [i for i in x if len(i) == 4]



Related Posts


No comments :

Post a Comment