私信  •  关注

Jack Hamby

Jack Hamby 最近创建的主题
Jack Hamby 最近回复了
7 年前
回复了 Jack Hamby 创建的主题 » 如何在Python中找到给定字符的最大重复子串?

不是最有效的,而是一个简单的解决方案:

word = "aasfgaaassaasdsddaaaaaafff"

substr_count = 0
substr_counts = []
character = "f"
for i, letter in enumerate(word):
    if (letter == character):
        substr_count += 1
    else:
        substr_counts.append(substr_count)
        substr_count = 0
    if (i == len(word) - 1):
        substr_counts.append(substr_count)

print(max(substr_counts))


7 年前
回复了 Jack Hamby 创建的主题 » python中的字符串搜索-两个列表

这应该能实现你想要的,

A =  ['abcbdefcd']

T =  ['ab', 'abc', 'def', 'cd', 'abcd']

result = False
for text in A:
    for sub_text in T:
        if (sub_text in text):
            result = True
            break

if (result):
    print('True')
else:
    print('False')