2

I am trying to figure out how to delete an item from my list that I created with possible_values = sp.range(0, 100, step = 1) I have tried possible_values.pop(index), that doesnt work. I have tried del possible_values[index], that didnt work. It also doesnt seem to let me define by index such as possible_values[index] = -1. Is this possible to do with a list or will I need to use a map? Also If I need to use a map how do I create a range with a map?

2

It’s not possible to do random access or edition on lists. The only reasonable building block that you have is matching the first element.

https://smartpy.io/docs/types/lists/#match-a-list-and-expose-its-head-and-tail

Maps and sets are much better structures if you want to add and remove elements.

About range/map. In full generality, you need to do it with a for loop. See example in the init method of https://smartpy.io/ide?template=state_channel_games/models/nim.py. Note that you also need a local variable.

If your map has always the same shape and size (and doesn’t depend on any dynamic parameter) when you create it; you can also simply expose it directly as you would do in Python (with a constant, dict comprehension, etc.). This would inline the map inside your Michelson code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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