Skip to content
Advertisement

How to skip some results using double for loop?

I have a problem, so I made it simplified code, everything how it is here need to stay that way because of my bigger problem. I have 2 dictionaries and I have 2 for loops. I need to skip outputs with same result like AA, BB, CC etc… and I need to remove one of AB or BA, I need to keep AB, but I don’t need BA. Can you help me with this problem, but I need to keep it simple for my real problem?

JavaScript

Output:

JavaScript

‘*’ it’s not output, outputs with * I want to skip

Thanks in advance!

Advertisement

Answer

You can just keep the pairs where bot < top. This will discard the duplicates where top < bot, as well as the pairs where top == bot.

JavaScript

There’s no need to use .items() if you’re only using the values, not the keys.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement