a=input()
max_count=[]
def zichuan(input_a):
count=[]
for i in input_a:
if i not in count:
count.append(i)
else:
input_a=input_a[1:]
max_count.append(''.join(count))
zichuan(input_a)
return
max_count.append(''.join(count))
return
zichuan(a)
m=list(map(len,max_count))
n=m.index(max(m))
the_max=max_count[n]
print(max_count,the_max,n,max(m))
输入:a12ac16
输出为
['a12', '12ac', '2ac16'] 2ac16 2 5
输入:
aabbccddefghbbb
输出:
['a', 'ab', 'b', 'bc', 'c', 'cd', 'd', 'defghb', 'efghb', 'fghb', 'ghb', 'hb', 'b', 'b', 'b'] defghb 7 6
#
总结:
1.迭代方法下面一定要立马接上return 否则进入迭代的前期参数会保留对后面产生影响
2.使用迭代与for遍历方法结合时 return一般会使用两次 返回遍历完成的结果
3.map函数要加list () ,且注意为()
补充 :list(map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10]))
4.索引位置用index 注意为列表索引元素为list[]