例如:
def matching_names(name1, name2):
""" (list of str, str) -> list of str
和name1的格式为' firstname lastname', 如果我希望它返回name1等于name2的name1列表,我该怎么办?
离)
matching_names(['sarah james', 'rebecca black', 'rebecca kim'], 'rebecca')
[' rebecca black',' rebecca kim']
答案 0 :(得分:0)
def matching_names(name1, name2):
a = []
for name in name1:
if name.split(" ")[0] == name2:
a.append(name)
return a
答案 1 :(得分:0)
results = []
for entry in name1:
if entry.split()[0] == name2:
results.append(entry)
return results