Quantcast
Viewing all articles
Browse latest Browse all 14155

Return more than 2 duplicates in each sublist (2d list)

I have a large 2d list that has duplicates in some sublists. I would like to return 2 or more duplicates and return the duplicates first if impossible. For instance,

Df =[[2,3,5,20],[5,10,20,10],[4,13,15,15,17,34,17],[33,34,15,21][12,16,24,32,12,33,24]]

I would like my result like this:

Df2 = [[15,17,4,13,34],[12,24,16,32,33]]

I have tried this code below but I only would to return the duplicates that has 2 or more duplicates.

res = [t for t in Df if len(t) > len(set(t))]


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>