Transcrypt
Transcrypt copied to clipboard
del has Javascript behaviour when used on a list item
The Python del
results in the Javascript delete
, which doesn't have the same behaviour on a list item as in Python. try:
t = [1,2,3]
del(t[0])
print(len(t))
In Python you get length 2, and in Javascript length 3. Javascript's t.splice(0,1)
could solve the problem.
That or t.pop(0)
.
I have encountered the same problem still. Is there a plan to fix it?
I've used del
in other ways and it seems to work, but it might behave differently with list elements. I can check into it.
I've used
del
in other ways and it seems to work, but it might behave differently with list elements. I can check into it.
yes, for list/array it is translated as "delete" in JS and according to Mozzila docs it's behaviour is to delete the item and leave an empty slot resulting in sparse array. My case was that after item removal "for i, x enumerate(myList)" failed to iterate the list/array. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#deleting_array_elements