strings = ['a', 'apple', 'b', 'beta', 'c', 'd']
def prefices_only(strlist):
ordered = sorted(strlist)
last = ordered[0]
results = [last]
for c in ordered:
if not c.startswith(last):
last = c
results.append(c)
return results
print(prefices_only(strings))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152 次 |
| 最近记录: |