2021年3月14日星期日

How to select the duplicate and unique values from multiple list

How to create an other list which contains most repeated items from all the list on the top and unique items below. I tried it with for loop but I can only compare list1 with rest where I'm missing the items in rest of them. How to solve this. Thank You.

    repeated_list = []      non_repeated_list = []            for item in List1:         if item in List2:            if item in List3:               repeated_list.append(item)            else:               non_repeated_list.append(item)      List1 = [Apple, Banana, Mango, Grapes, Orange]        List2 = [Car, Bike, Mango, Truck, Orange]        List3 = [watermelon, Banana, Bus, Grapes, Truck]    Solution:    repeated_list = [Banana,Mango,Orange,Grapes]    non_repated_list = [Apple,Car,Bike...etc]  

Then merging the two list but the problem is I cannot include unique items of other list as I loop and compare with list1 only. So how to include other unique items from other list as well.

https://stackoverflow.com/questions/66631245/how-to-select-the-duplicate-and-unique-values-from-multiple-list March 15, 2021 at 09:24AM

没有评论:

发表评论