Menu

gitpiper

initialize_2d_list python Code Snippet in 2024

listintermediate

Last Updated: 16 September 2024

Initializes a 2D list of given width and height and value.

  • Use a list comprehension and range() to generate h rows where each is a list with length h, initialized with val.
  • Omit the last argument, val, to set the default value to None.
def initialize_2d_list(w, h, val = None): return [[val for x in range(w)] for y in range(h)]
initialize_2d_list(2, 2, 0) # [[0, 0], [0, 0]]

python snippet similar to initialize_2d_list For You in September 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️