About 286,000 results
Open links in new tab
  1. Create an empty list with certain size in Python - Stack Overflow

    To create a list of size 10(let's say), you can first create an empty array, like np.empty(10) and then convert it to list using arrayName.tolist(). Alternately, you can chain them as well. …

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

    Nov 30, 2015 · After hours of struggle want to note that apparently comprehension for creation of a list of lists [[] for _ in range(N)] behaves differently creation of list of empty strings ["" for _ in …

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

    % python -mtimeit "l=[]" 10000000 loops, best of 3: 0.0711 usec per loop % python -mtimeit "l=list()" 1000000 loops, best of 3: 0.297 usec per loop However, in practice, this initialization …

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

    @ReslanTinawi It's not about the keys. If you would add something to the list corresponding to the first key, then it would also be added to the lists belonging to the other keys; because they all …

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

    It is also possible to create an empty array with a certain size: array = [[] for _ in range(n)] # n equal to your desired size array[0].append(5) # it appends 5 to an empty list, then array[0] is …

  6. python - Creating an empty Pandas DataFrame, and then filling it ...

    pd.DataFrame converts the list of rows (where each row is a scalar value) into a DataFrame. If your function yields DataFrames instead, call pd.concat. Pros of this approach: It is always …

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

    Anyway, the reason this is bad (and that violating idioms in a language with strong idioms like Python is bad in general) is that it signals to the reader that you're specifically checking the …

  8. python - How to empty a list? - Stack Overflow

    Feb 10, 2020 · This actually removes the contents from the list, but doesn't replace the old label with a new empty list: del lst[:] Here's an example: lst1 = [1, 2, 3] lst2 = lst1 del lst1[:] print(lst2) …

  9. How to create a number of empty nested lists in python

    I want to have a variable that is a nested list of a number of empty lists that I can fill in later. Something that looks like: my_variable=[[], [], [], []] However, I do not know beforehand how...

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

    May 23, 2020 · I'm new to python and I've seen two different ways to initialize an empty list: # way 1 empty_list = [] # way 2 other_empty_list = list() Is there a "preferred" way to do it? Maybe …

Refresh