codewars[7]-python Friend or Foe?

it2025-11-08  8

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

最新回复(0)