About 2,260,000 results
Open links in new tab
  1. Python – Create List of Size n - GeeksforGeeks

    Dec 10, 2024 · Creating a list of size n in Python can be done in several ways. The easiest and most efficient way to create a list of size n is by multiplying a list. This method works well if we want to fill the list with a default value, like 0 or None.

  2. Create a list with initial capacity in Python - Stack Overflow

    pre_allocated_list = [None] * size to preallocate a list (that is, to be able to address 'size' elements of the list instead of gradually forming the list by appending). This operation is very fast, even on big lists.

  3. Initialize a List of Any Size with Specific Values in Python

    Nov 19, 2024 · In Python, we often need to create a list with a specific size and initialize all elements with the same value. This is useful when we want to set up a list but don't yet have the exact values we need. There are several ways to do this. Let’s start with the simplest way to create a list with repeated values using Python. Using Multiplication

  4. Initialising an array of fixed size in Python - Stack Overflow

    I would like to know how i can initialize an array(or list), yet to be populated with values, to have a defined size. For example in C: int x[5]; /* declared without adding elements*/ How do I do that in Python?

  5. How to Initialize a List of Size N in Python? - Python Guides

    Mar 3, 2025 · Learn how to initialize a list of size N in Python using list multiplication, list comprehension, and `range()`. This guide includes step-by-step examples.

  6. Initialise a list to a specific length in Python - Stack Overflow

    I'm searching for a good-looking way to initialize a empty list with a specific range. So make a list that contains 10 zeros or something to be sure that my list has a specific length. If the "default value" you want is immutable, @eduffy's suggestion, e.g. [0]*10, is good enough.

  7. Create a List of Size n in Python - Python Examples

    Learn how to create a list of a specified size in Python, initialized with a given value. This tutorial includes examples for creating integer, string, and None value lists.

  8. Python: How to Initialize List of Size N - Techgeekbuzz

    Feb 11, 2025 · In this Python tutorial, we will discuss two different techniques you can use to initialize a list of size n. Suppose you want to create a list that holds the top 10 students' Names from a grade based on their score. And for that, you need a list of a fixed length of 10 elements.

  9. Python: Creating Lists of a Specified Size - CodeRivers

    Apr 12, 2025 · Sometimes, we need to create a list with a specific size, either to pre - allocate space for future elements or to initialize a list with a known number of elements of a particular value. This blog post will explore various ways to create lists of a specified size in Python, along with best practices and common use cases.

  10. How to Create a List With a Specific Size in Python

    Feb 2, 2024 · Python offers several ways to create a list of a fixed size, each with different performance characteristics. To compare performances of different approaches, we will use Python’s standard module timeit. It provides a handy way to measure run times of small chunks of Python code. Preallocate Storage for Lists

  11. Some results have been removed
Refresh