Last active
April 19, 2020 02:47
-
-
Save DDuarte/beba7b1bdff423cc92512de3e80ddc48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re as e | |
import sys as y | |
from collections import defaultdict as d | |
o,r=sorted,d(set) | |
[r["".join(o(w))].add(w)for w in e.split("\W"," ".join(y.stdin).lower())if len(w)==int(y.argv[1])] | |
[print(w+": "+",".join(o(r[w])))for w in o(r)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re as e | |
import sys | |
from collections import defaultdict as d | |
def ana(n: int, s: str) -> str: | |
o,r=sorted,d(set) | |
[r["".join(o(w))].add(w)for w in e.split("\W",s.lower())if len(w)==n] | |
return "\n".join([w+": "+",".join(o(r[w]))for w in o(r)]) | |
if __name__ == "__main__": | |
print(ana(int(sys.argv[1]), " ".join(sys.stdin))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ana import ana | |
def test_1(): | |
s = "Thou hast ignore the region where the ringer and the singer resigns. The signer, Has Kell" | |
assert ana(6, s) == "eginor: ignore,region\neginrr: ringer\neginrs: signer,singer" | |
def test_2(): | |
s = "Thou hast ignore the region where the ringer and the singer resigns. The signer, Has Kell" | |
assert ana(4, s) == "ahst: hast\nekll: kell\nhotu: thou" | |
def test_3(): | |
s = "Thou.hast.ignore.the.region.where.the.ringer.and.the.singer.resigns.The.signer,Has.Kell!" | |
assert ana(4, s) == "ahst: hast\nekll: kell\nhotu: thou" | |
def test_4(): | |
s = "Thou hast ignore the region where the ringer and the singer resigns. The signer, Has Kell" | |
assert ana(2, s) == "" | |
def test_5(): | |
s = "cab" | |
assert ana(3, s) == "abc: cab" | |
def test_6(): | |
s = "" | |
assert ana(3, s) == "" | |
def test_7(): | |
s = "cba aaaa abc bbbb abc bca zzzz" | |
assert ana(3, s) == "abc: abc,bca,cba" | |
def test_8(): | |
s = "bca bcd abc acb cdb the abc" | |
assert ana(3, s) == "abc: abc,acb,bca\nbcd: bcd,cdb\neht: the" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment