Last active
August 4, 2020 18:21
-
-
Save nbertagnolli/c85248ef76cd5d82bbacfb1a0464b34c to your computer and use it in GitHub Desktop.
Converts a positive integer to its unsigned bianry representation as a list
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
from typing import List | |
def create_binary_list_from_int(number: int) -> List[int]: | |
if number < 0 or type(number) is not int: | |
raise ValueError("Only Positive integers are allowed") | |
return [int(x) for x in list(bin(number))[2:]] |
Sorry it's mypy type annotation : ). Just add from typing import List
to the top. I'll add it in. Thanks for pointing that out!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get an error: name 'List' is not defined. Can't seem to fix it, can you help?