This question already has answers here:
Determine prefix from a set of (similar) strings
(8个答案)
3年前关闭。
是否有一个函数返回列表中所有值开头的最长字符串的(长度):
应该返回:
为此:
(8个答案)
3年前关闭。
是否有一个函数返回列表中所有值开头的最长字符串的(长度):
["flexible","flexile","flexion","flexor"]
应该返回:
"flex"
或4为此:
["flexible","flexile","flexion","flexor","ape"]
,它应该返回一个空字符串或0; 最佳答案
>>> import os
>>> os.path.commonprefix(["flexible","flexile","flexion","flexor"])
'flex'
10-04 11:02