Alternative to Double Iteration
iteration, python
Solution
You don't have to find the removed values first. Just create the list you need in one shot:
my_list = [y for y in my_list
if not any(meets_requirement(x,y) for x in my_list)]
Problem
I have a procedure which requires me to check each value in a List against every other value in the same List. If I identify something that meets some requirement, I add it to another List to be removed after this procedure is finished. Pseudo-code: ``` for value1 in my_list: for value2 in my_list: if meets_requirements(value1, value2): to_be_removed.append(value2) ``` This looks ugly to me. Naming conventions for the variables are difficult to assign or understand. There's the potential (although very un-likely, in this case) I could accidentally modify the list while iterating it. There may be issues with performance. Is there a better alternative to performing these double iterations? If not, are there any ways I can make this more readable and "feel" like quality code?