About 50 results
Open links in new tab
  1. python - How to empty a list? - Stack Overflow

    Feb 10, 2020 · 224 If you're running Python 3.3 or better, you can use the clear() method of list, which is parallel to clear() of dict, set, deque and other mutable container types:

  2. 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:

  3. performance - Creating an empty list in Python - Stack Overflow

    What is the best way to create a new empty list in Python? l = [] or l = list() I am asking this because of two reasons: Technical reasons, as to which is faster. (creating a class causes overhe...

  4. python - How to create a list of empty lists - Stack Overflow

    Nov 30, 2015 · This is not what the questions asks for. This creates a list of lists with zeros, not a list of empty lists. That builds a Numpy array, not a list.

  5. How do I get an empty list of any size in Python? - Stack Overflow

    155 I basically want a Python equivalent of this Array in C: int a[x]; but in python I declare an array like: a = [] and the problem is I want to assign random slots with values like: a[4] = 1 but I can't do that with …

  6. python - How do I check if a list is empty? - Stack Overflow

    If you need to do more than just check if the input is empty, and you're using other NumPy features like indexing or math operations, it's probably more efficient (and certainly more common) to force the …

  7. How can I make an empty list of size 4 in python? [duplicate]

    Jun 19, 2022 · The List in Python is not an Array of fixed-size upon declaration, so it is by design variable in size. Meaning you can just append members into it. Much like ArrayLists in Java!

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

    How to initialize a dict with keys from a list and empty value in Python? Ask Question Asked 16 years ago Modified 3 years, 1 month ago

  9. python - How to define an empty 2 dimensional list instead of data

    Jun 21, 2022 · My approach to this problem would use NumPy, a math and data manipulation library for python. In that library, there's a very simple way of accomplishing this. If I want to generate an empty …

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

    You can arrange data in an array like structure in default Python but it's not nearly as efficient or useful as a NumPy array. Especially if you want to deal with large data sets.