Hello, I don't know python. I've put together bits of code from the web to sort lines by the length of strings, i.e. to sort these lines:
stri stri string string1 string1 s st str
into these (removing duplicates also):
string1 string stri str st s
Is there a way to streamline the following code i'm using, or maybe a simpler way to achieve the same result? Thanks
editor.beginUndoAction() lines = {} if (editor.getSelText()): hm = editor.getSelText().splitlines() howmanyLines = len(hm) else: hm = editor.getLineCount() howmanyLines = hm for line in range(0, howmanyLines): strippedLine = editor.getLine(line).rstrip('\r\n ') if len(strippedLine) in lines: continue else: lines[len(strippedLine)]=[strippedLine] editor.clearAll() for l in reversed(sorted(lines)): console.write( "\r\n".join(reversed(sorted(lines[l]))) ) print "\r\n".join(reversed(sorted(lines[l]))) editor.endUndoAction()
Hello, I've posted a new script here. For this reason I'm going to close this thread. Please, refer to this link in future: https://sourceforge.net/projects/notepad-plus/forums/forum/1290590/topic/6056194 Best regards fb16
Log in to post a comment.
Hello,
I don't know python. I've put together bits of code from the web to sort lines by the length of strings, i.e. to sort these lines:
into these (removing duplicates also):
Is there a way to streamline the following code i'm using, or maybe a simpler way to achieve the same result? Thanks
Hello,
I've posted a new script here. For this reason I'm going to close this thread. Please, refer to this link in future:
https://sourceforge.net/projects/notepad-plus/forums/forum/1290590/topic/6056194
Best regards
fb16