测试
a=("ab/cd/ef", "ab/cd/ef/g", "ab/cd/")
输出
{'ab/cd/': 1}
[code]
#in_set 应是一个有序的字符串集合
def remove_duplicate_string(in_set):
if len(in_set) < 2:
return in_set
duplicate_str_dict = {}
same_str_dict = {}
old_str = ""
same_str = ""
for str in in_set:
if len(same_str) > 1:
if str.find(same_str) >= 0: # same_str 应该是两个字符串的交集,如果能跟same_str匹配,则直接pass
continue
if len(old_str) > 0:
same_str = get_same_string(old_str, str)
print(f"{same_str} vs {old_str} vs {str}")
if len(same_str) > 1:
same_str_dict[same_str] = 1
old_str = str
if len(same_str_dict) < 1 or len(same_str_dict) == len(in_set):
return in_set
if len(same_str_dict) < len(in_set):
return remove_duplicate_string(same_str_dict)
return same_str_dict
[/code]
2021-10-07
python批量提取一个set中,最小相同路径
Comments Off on python批量提取一个set中,最小相同路径
No Comments
No comments yet.
RSS feed for comments on this post.
Sorry, the comment form is closed at this time.