Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Is it a bug? Why deleting an argument in an array gets null?

On this level, I cleared out all the other code lines and did this below. Please take a look the lines and my #s.

friends = hero.findFriends()

#says 'comet'
#says 'vixen'
#says 5

del friends[3]

#should says 4... but still 5

#should says 'vixen'... but no.
#Line 15: ArgumentError: say's argument message should have type string, but got null. Say what?

So basically it’s like [1, 2, 3] - [2] got [1, null, 3], which should have been [1, 3] I guess.

When you delete arguments from an array, shouldn’t the array’s length get short by the number of argument you just deleted, instead of putting NULL to keep the length?

No, it’s not a bug, it’s CodeCombat Python, not pure python. CoCo python is JavaScript in dis guise:-). You can use many javascript features as filter, map, LoDash etc…, but I think the inverse will generally not work, as some exepected python code will act as javascript code.

1 Like

Thank you very much :smiley:

OMG! This works in CoCo:

x = ['a', 'b','c']
index = x.index('c')
del x[index]

browser console output:

['a', 'b', 'c']
['b', 'c']
['b',]  # in python console it will be ['b']