0 votes

[copied from GT FB group]

Is there a way to remove from a collection?

like thing.add(otherthing)

Essentially I want to move things from list2 to list2 incrementally.

e.g.

>> things.shuffle
>> otherthings.add(things[1])
>> things.remove(1)

 

by (5.8k points)

1 Answer

0 votes

You can use the new functions .erase and .remove.

.erase removes something at a given index, for example:

>>friends = ["Liz", "Ana", "Sam"]
>>friends.remove(2)

The code above will remove the second element from the collection (the one with value "Ana")

.remove will remove all of the elements that match a give value:

>>tripsThisYear = ["Paris", "London", "Rome", "London", "Madrid"]
>>tripsThisYear.erase("London")

If you run the code above you will see that the function removes the two elements with value "London"

by (1.4k points)
Welcome to Guidedtrack Q&A, where you can ask questions and receive answers from other members of the community.
111 questions
118 answers
51 comments
310 users