Skip to content

Instantly share code, notes, and snippets.

@nbertagnolli
Last active August 4, 2020 18:21
Show Gist options
  • Save nbertagnolli/c85248ef76cd5d82bbacfb1a0464b34c to your computer and use it in GitHub Desktop.
Save nbertagnolli/c85248ef76cd5d82bbacfb1a0464b34c to your computer and use it in GitHub Desktop.
Converts a positive integer to its unsigned bianry representation as a list
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:]]
@Smith-debug
Copy link

I get an error: name 'List' is not defined. Can't seem to fix it, can you help?

@nbertagnolli
Copy link
Author

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