a = 'pwwkew'
def longest_substring(string, substring_len):
for i in range(len(a) - substring_len + 1):
substring = list(a[i:i + substring_len])
if sorted(substring) == sorted(set(substring)):
# Условие выполняется
return substring
longest_substring(string, substring_len - 1)
ans = longest_substring(a, len(a))
print(ans) # --> None
def longest_substring(string, substring_len):
for i in range(len(a) - substring_len + 1):
substring = list(a[i:i + substring_len])
if sorted(substring) == sorted(set(substring)):
return substring
return longest_substring(string, substring_len - 1)