[Solved] Two list count specific elements and aggregate on spefic rule [closed]
There are many possible solutions. In my opininion this is the easiest: import heapq list1 = [2,5,7] list2=[4,6,9] counter1=0 counter2=0 sum1=0 sum2=0 full_list = list1 + list2 three_largest = heapq.nlargest(3,full_list) for n in three_largest: if n in list1: list1.remove(n) counter1+=1 sum1+=n else: list2.remove(n) counter2+=1 sum2+=n print(counter1) print(counter2) print(sum1) print(sum2) Note that you made a mistake … Read more