notepad++ pythonScript插件之去重并排序实现

import StringIO

def sortlist(list0):
    list0.sort()
    last=list0[-1]
    for i in range(len(list0)-2,-1,-1):
        if list0[i]==last:
            list0.remove(list0[i])
        else:
            last=list0[i]
    return list0

contextList = []

allText = ""
selectText = editor.getSelText() 
lineIndex = 0
javaText = ""
for line in StringIO.StringIO(selectText):
    #console.write(line)
    if line.strip() not in contextList and line.strip() <> "":
        contextList.append(line.strip()+"\n")

sortl = sortlist(contextList)

for a in sortl:
    allText = allText + a 

editor.setText(allText)

你可能感兴趣的:(工具,python)