Skip to content

Instantly share code, notes, and snippets.

@DDuarte
Last active April 19, 2020 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DDuarte/beba7b1bdff423cc92512de3e80ddc48 to your computer and use it in GitHub Desktop.
Save DDuarte/beba7b1bdff423cc92512de3e80ddc48 to your computer and use it in GitHub Desktop.
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)]
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)))
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