def find_max_substr(astring): max_sub_str, temp = [], [] left_ptr, right_ptr = 0, 0 total = len(astring) while right_ptr < total: cur_str = astring[right_ptr] if cur_str not in temp: temp.append(cur_str) right_ptr += 1 else: if len(temp) > len(max_sub_str): max_sub_str = temp index = temp.index(cur_str) left_ptr = left_ptr+index+1 temp = [astring[j] for j in range(left_ptr, right_ptr)] if len(temp) > len(max_sub_str): max_sub_str = temp return max_sub_str astring = 'asdfabcefghijk' ret = find_max_substr(astring) print(''.join(ret), len(ret))