How to make a list of n-lists in Python

Making a list of n-lists results in a list with n-items, where each item is the same list. For instance, making a list containing 5 lists, with each list being [1,2], results in [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2]].

Solution for How to make a list of n-lists in Python : You can use range() to make a list of n-lists in Python Use range(start, stop) with start as 0 and stop as the desired amount of lists within the list. Use a for-loop to iterate through this range. In each iteration, use list.append(item) where list is an initially empty list and item is another list.

Use a list comprehension for a more compact implementation.

list2 = [1,2]


how-to-make-a-list-of-n-lists-in-python