Pythonを使用して、文字列からアルファベット順に最長の文字列を抽出します



Use Python Extract Longest String Alphabetical Order From String



これは、MITのPythonを使用した計算とプログラミング入門コースの放課後の演習です。
より良い解決策があるかどうかはわかりません。あなたはポインタを与えることができます。

# Output the longest string in alphabetical order in teststr servilize = 'abcdefghigklmnopqrstuvwxyz' teststr = 'abcbcd' tempstr = '' str = '' tempservilize = 'abcdefghigklmnopqrstuvwxyz' for i in teststr: if i in tempservilize: site = servilize.find(i) tempservilize = servilize[site + 1:] tempstr += i else: if len(tempstr) > len(str): str = tempstr tempstr = i tempservilize = servilize site = tempservilize.find(i) tempservilize = tempservilize[site + 1:] print str