Skip to content

Instantly share code, notes, and snippets.

@raviolliii
Created August 20, 2019 05:24
Show Gist options
  • Save raviolliii/55a6459c651ff606099ba6375375bb01 to your computer and use it in GitHub Desktop.
Save raviolliii/55a6459c651ff606099ba6375375bb01 to your computer and use it in GitHub Desktop.
def is_smaller(one, two):
one_sorted = sorted(one)
one_freq = [one.count(l) for l in sorted(set(one_sorted))]
two_sorted = sorted(two)
two_freq = [two.count(l) for l in sorted(set(two_sorted))]
for oc, tc in zip(one_freq, two_freq):
if oc != tc:
return oc - tc < 0
return False
def compare_strings(A, B):
list_a = A.split(", ")
list_b = B.split(", ")
res = []
for b in list_b:
smaller = [int(is_smaller(a, b)) for a in list_a]
res.append(sum(smaller))
return res
res = compare_strings("abcd, aabc, bd", "aaa, aa")
# res: [3, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment