About 133,000 results
Open links in new tab
  1. Best and/or fastest way to create lists in python

    In python, as far as I know, there are at least 3 to 4 ways to create and initialize lists of a given size: Simple loop with append: my_list = [] for i in range(50): my_list.append(0) Simple ...

  2. Initializing a list to a known number of elements in Python

    Feb 7, 2009 · Instead of initializing the list with a single element (e.g. None) and a fixed length to avoid list resizing, you should consider using list comprehensions and directly fill the list with …

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

    Closed 9 years ago. How do I initialise a list with 10 times a default value in Python? I'm searching for a good-looking way to initialize a empty list with a specific range. So make a list that …

  4. Create an empty list with certain size in Python - Stack Overflow

    How do I create an empty list that can hold 10 elements? After that, I want to assign values in that list. For example: xs = list() for i in range(0, 9): xs[i] = i However, that gives IndexError:

  5. How to initialize a two-dimensional array (list of lists, if not using ...

    I'm beginning python and I'm trying to use a two-dimensional list, that I initially fill up with the same variable in every place. I came up with this: def initialize_twodlist(foo): twod_list ...

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

    In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be …

  7. What is the best practice to initialize an empty list in python ( [] or ...

    May 23, 2020 · Closed 5 years ago. I'm new to python and I've seen two different ways to initialize an empty list:

  8. How to initialize a dict with keys from a list and empty value in …

    How to initialize a dict with keys from a list and empty value in Python? Asked 15 years, 10 months ago Modified 2 years, 10 months ago Viewed 531k times

  9. python - Why does this code for initializing a list of lists apparently ...

    This question is about how to initialize a list of independent lists. The other question is about why the [ [ ] ] * n results in "linked" new list behavior. The answers are different, and for those …

  10. Create list of single item repeated N times - Stack Overflow

    Apr 16, 2024 · 826 I want to create a series of lists, all of varying lengths. Each list will contain the same element e, repeated n times (where n = length of the list). How do I create the lists, …