Created
May 19, 2023 09:04
-
-
Save kaspermunch/b99971c7f820ef7df3683859f3c8c1b6 to your computer and use it in GitHub Desktop.
Burrows+Wheeler transform
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
def burrows_wheeler_transform(text): | |
# Create a list of all rotations of the input text | |
rotations = [text[i:] + text[:i] for i in range(len(text))] | |
# Sort the list of rotations in lexicographic order | |
rotations.sort() | |
# Return the last characters of each rotated string, which is the | |
# Burrows-Wheeler transform of the input text | |
return “”.join([rot[-1] for rot in rotations]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment