Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| # Question: "Given two strings, write a function to determine whether they are anagrams" | |
| from itertools import groupby | |
| from operator import itemgetter | |
| sorted_histogram = lambda s: sorted([(lower(k), len(list(g))) for k, g in groupby(s)], key=itemgetter(0)) | |
| isAnagram = lambda s1, s2: sorted_histogram(s1) == sorted_histogram(s2) | |
| assert isAnagram("", "") == True | |
| assert isAnagram("A", "A") == True | |
| assert isAnagram("A", "B") == False |
This file contains hidden or 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
| # https://www.byte-by-byte.com/stringcompression/ | |
| # Question: "Given two strings, write a function to determine whether they are anagrams." | |
| from itertools import groupby | |
| compress = lambda s: min(("".join([f"{k}{len(list(g))}" for k, g in groupby(s)]), s), key=lambda s_: len(s_)) | |
| assert compress(“a”) == "a" | |
| assert compress(“aaa”) == "a3" | |
| assert compress(“aaabbb”) == "a3b3" | |
| assert compress(“aaabccc”) == "a3b1c3" |
This file contains hidden or 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
| """ | |
| https://github.com/tqdm/tqdm | |
| https://stackoverflow.com/questions/38543506/change-logging-print-function-to-tqdm-write-so-logging-doesnt-interfere-wit/38739634 | |
| https://stackoverflow.com/questions/36986929/redirect-print-command-in-python-script-through-tqdm-write | |
| https://stackoverflow.com/questions/566746/how-to-get-linux-console-window-width-in-python | |
| """ | |
| import logging | |
| import time | |
| import tqdm |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 itertools as IT | |
| # https://stackoverflow.com/questions/3992735/python-generator-that-groups-another-iterable-into-groups-of-n/3992765 | |
| # https://stackoverflow.com/questions/31164731/python-chunking-csv-file-multiproccessing/31170795#31170795 | |
| # https://docs.python.org/3/library/functions.html#iter | |
| def grouper(n, iterable): | |
| """ | |
| >>> list(grouper(3, 'ABCDEFG')) | |
| [['A', 'B', 'C'], ['D', 'E', 'F'], ['G']] | |
| """ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.