Skip to content

Home

Initialize list with values

Initializes and fills a list with the specified value.

def initialize_list_with_values(n, val = 0):
  return [val for x in range(n)]

initialize_list_with_values(5, 2) # [2, 2, 2, 2, 2]

More like this

Start typing a keyphrase to see matching snippets.