codewars[7]-python Friend or Foe?

list中保留四字母的,然后return。

def friend(x):
i = len(x)
ii = []
a = 0
while a < i:
if len(x[a]) == 4:
ii.append(x[a])
a += 1
return ii

别人的超pythonic的题解。。

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

原文地址:https://www.cnblogs.com/ruoh3kou/p/8516747.html