Skip to content

Instantly share code, notes, and snippets.

@icio

icio/a_by_b.py Secret

Created October 5, 2013 14:58
Show Gist options
  • Save icio/6191f2ce019c9c795a30 to your computer and use it in GitHub Desktop.
Save icio/6191f2ce019c9c795a30 to your computer and use it in GitHub Desktop.
def a_by_b(a, b):
b = {c:p for p, c in enumerate(reversed(b+a))}
return "".join(sorted(a, lambda l, r: b[r] - b[l]))
a = "adlkfhxaxjxkxhxfwkhkjfhjkahjksedeheflhadslfkhdfjkadhjhdhskghdjdjkhskkhjokhkshakhlhfkjdshjfkshhkskskss"
b = "alskdjfhg"
assert a_by_b(a, b) == "aaaaaallllssssssssssskkkkkkkkkkkkkkkkkkkkdddddddddjjjjjjjjjjjffffffffhhhhhhhhhhhhhhhhhhhhhgxxxxxweeeo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment