Created
October 26, 2020 13:42
-
-
Save les-peters/304f0dec11e042fa8791d7c4a35d934f to your computer and use it in GitHub Desktop.
Sort by bits
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
import re | |
arr = [0,1,2,3,4,5,6,7,8] | |
arr.sort(key=lambda x: len(re.sub(r'0','', "{0:b}".format(x)))) | |
print(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment