Yes, this sort of thing can be done but the nested loop answer raises some concerns.
First, the OP is silent on whether we are addressing memory variables or state variables. From the proposed solution, I gather the idea is about processing transient state variables. That should be avoided. It is almost certainly an inappropriate division of labour to use expensive contract execution for this purpose. See this: https://blog.b9lab.com/the-joy-of-minimalism-in-smart-contract-design-2303010c8b09
Most good patterns will work with state variables. To be scalable, the algorithm should complete with the same maximum gas cost at any scale. Unbounded
for loops are an anti-pattern. Nested unbounded
for loops are like anti-pattern squared. If there is a finite maximum number of elements then it is not "unbounded", but the OP doesn't mention this. https://blog.b9lab.com/getting-loopy-with-solidity-1d51794622ad
You can delete elements from unordered sets with the Mapped Structs with Delete-enabled Index pattern shown here: Are there well-solved and simple storage patterns for Solidity?
Explainer covers why it works the way it does: https://medium.com/robhitchens/solidity-crud-part-1-824ffa69509a
Library compatible with solidity 0.5.x here: https://github.com/rob-Hitchens/UnorderedKeySet
Hope it helps.