I wanna delete the values of the list
lists = [12,15,15,15,3,15,1,6,4,7,888,56248]
while len(lists) is True:
lists.pop()
print(lists)
But i got this output :
[12, 15, 15, 15, 3, 15, 1, 6, 4, 7, 888, 56248]
I wanna delete the values of the list
lists = [12,15,15,15,3,15,1,6,4,7,888,56248]
while len(lists) is True:
lists.pop()
print(lists)
But i got this output :
[12, 15, 15, 15, 3, 15, 1, 6, 4, 7, 888, 56248]
The problem here is in your conditional
while len(lists) is True:
is
checks for identity, not equality.
[1, 2, 3] == [1, 2, 3] # True
[1, 2, 3] is [1, 2, 3] # False, they are two distinct (but equivalent) lists.
However even equality would be incorrect here, since
42 == True # False
2 == True # False
any_nonzero == True # False
# notably 1 == True
# and 0 == False
# but still (1 is True) == False!
You can coerce an integer into a boolean
bool(42) == True # True
bool(2) == True # True
bool(any_nonzero) == True # True
But it's usually better to just leave the coercion to Python
while lists:
lists.pop()
# or more simply:
# lists = []
If by "delete" you mean removing the element and reducing the list, you can iterate through a copy of lists with a for loop:
for n in lists[:]:
lists.remove(n)
If, instead, you want to have a list of None (or 0) values as long as lists, you can do it like this:
newlists = [0] * len(lists)
As was suggested in the previous comment.