2

I would like to know what is the best way to remove an element inside a DynArray in vyper. Seems there is no functionalities like remove() or del(). Only pop() for the last element.

For example you have an array of addresses and you want to remove a specific address, how do you do ? And if it's not possible what's the best way to manage this problem ? Mappings ? Or other ?

1 Answer 1

2

Ok I found the answer myself. Just need to replace the element by the last element of the array and then delete this one. Like so :

self.user[indexToDelete] = self.user[len(self.user) - 1]
self.user.pop()

Hope it can help some of you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.