Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc"
-
@Alan-Kilborn said in Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc":
I could throw together yet another script to do it quickly, but it is probably better to just cite something that has previously been done.
Well, Peter violated this principle, but I’ve no problem with that! :-)
-
It took a bit to find it for some reason, but here’s basically the same script as Peter’s more recent one:
-
Thanks, but unless I’m not seeing something different between your code and mine, I think this is what I tried first. Won’t it give you the “aAAaBbbBCcCc” results? That is, it sorts the aA’s in the order they’re in in the file, and not alphabetical AND case order.
-
Sorry, didn’t notice that you wanted a combo of insensitive + sensitive.
Change the lambda expression. I think doing s.lower()+s will give you want you want. when it is comparing the
a
line to theA
line, the sort key will beaa
vsaA
, so it will put the upper-case first:editor.setText("\r\n".join(sorted(editor.getText().splitlines(), key=lambda s: s.lower()+s)))
=>
AAaaBBbbCCcc
-
Sorry, I also didn’t notice what was really wanted here. :-(
-
Your solution sounds like it should work! I hadn’t considered “+s”, so will test as soon as I can and close this issue.
Thanks to both of you.
-
@Alan-Kilborn said in Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc":
Sorry, I also didn’t notice what was really wanted here.
Since the only place he mentioned that he didn’t want that particular
aAAaBbbBCcCc
answer was in the “not” list in the title, I think we should be forgiven for not noticing. :-) -
@Alan-Kilborn said in Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc":
@Alan-Kilborn said in Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc":
I could throw together yet another script to do it quickly, but it is probably better to just cite something that has previously been done.
Well, Peter violated this principle, but I’ve no problem with that! :-)
Note that my googling for how to sort case-insensitive in python, coming up with a one liner myself, and then cleaning it up into a readable script took less time than trying to find a bit of code in this forum. I really like and appreciate this forum, but searching it is … not always helpful or efficient. :-)
-
Agreed. And it’s funny you say that, as I almost made my title “Sort “aCcBAbbAcaCB” as “aaAAbbBBccCC” or “AAaaBBbbCCcc” but not “AABBCCaabbcc”, “aabbccAABBCC”, or “aAAaBbbBCcCc””, and my post body “See title.”. :)
-
@VTGroupGitHub said in Sort as "aaAAbbBBccCC" or "AAaaBBbbCCcc" but not "AABBCCaabbcc", "aabbccAABBCC", or "aAAaBbbBCcCc":
as I almost made … my post body “See title.”
Thank you for not. That might’ve earned you a downvote on your OP from some users here, rather than getting you an answer. :-)