Skip to content
Advertisement

Sort a tuple with n elements based on a list with x elements

I have a tuple as given below

JavaScript

I want to sort this tuple based on this list

JavaScript

The sample of the expected output is given below

JavaScript

I tried the following solution given at here to sort a tuple based on list. But it doesnt give the desired outcome. I tried using explicit loop but it doesnt work. Any help is appreciated…

JavaScript

Advertisement

Answer

Here is solution you can try out, using sorted + groupby

JavaScript

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