Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

del has Javascript behaviour when used on a list item

Open darthglowball opened this issue 5 years ago • 4 comments

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.

darthglowball avatar Oct 07 '19 21:10 darthglowball

That or t.pop(0).

AlexECX avatar Oct 26 '19 18:10 AlexECX

I have encountered the same problem still. Is there a plan to fix it?

karna48 avatar Nov 14 '22 11:11 karna48

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.

JennaSys avatar Nov 14 '22 19:11 JennaSys

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

karna48 avatar Nov 15 '22 09:11 karna48