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

    Feb 10, 2020 · 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: alist.clear() # …

  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. python - How to create a list of empty lists - Stack Overflow

    Nov 30, 2015 · How to initialize a two-dimensional array (list of lists, if not using NumPy) in Python? (31 answers)

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

    Not very "pythonic", but it turns out that NumPy intentionally broke pythonicity in at least this sense. If you need to do more than just check if the input is empty, and you're using other …

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

    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 …

  6. 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 …

  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 …

    Do you intend for the dictionary to have None values for all keys? If so, why not use a set instead? The only reason that comes to mind for using a dict instead of set in this case is if you want to …

  9. How can I make multiple empty lists in Python? [duplicate]

    How can I make many empty lists without manually typing the following? list1=[], list2=[], list3=[] Is there a for loop that will make me 'n' number of such empty lists?

  10. python - How to fill an empty list with values from user input?

    Sep 8, 2019 · Okay, so I am at ground level in python, currently trying to do the following: I want to create a list of numbers received from user input, so for example I have an empty list and …

Refresh