Skip to content

Instantly share code, notes, and snippets.

@HoweChen
Created March 10, 2019 07:41
Show Gist options
  • Save HoweChen/b7782d3bd064a760cb353c0dd3827158 to your computer and use it in GitHub Desktop.
Save HoweChen/b7782d3bd064a760cb353c0dd3827158 to your computer and use it in GitHub Desktop.
[Initiate new list with default value]Initiage new list with default value #Python
target_num = 0
length = 100
# two methods
# 1
a = [target_num for x in range(length)]
# 2
b = [target_num] * length
length = 100
a=[[] for x in range(length)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment