from collections import Counter as cs l = cs([1, 2, 3, 3, 4]) z = [k if v == 1 else 'a' for k, v in l.items()] z.remove('a') print(z)
from collections import Counter as cs data = 'Python 3 is better than python 2'.split() count = cs(data) for i, j in sorted(count.items()): print(' ' * (10 - len(i)), end='') print('{} : {}'.format(i, j)) ''' 2 : 1 3 : 1 Python : 1 better : 1 is : 1 python : 1 than : 1 '''
from collections import Counter as cs x = int(input()) y = input().split(" ") y = cs(y) z = int(input()) l1, l2 = [], [] for i in range(z): q = input().split(" ") l1.append(q[0]) l2.append(q[1]) l3, l4 = [], [] for i in l1: if i not in l3: l3.append(i) l5 = [] for i in l3: l4 = [] for j in range(len(l1)): if i == l1[j]: l4.append(l2[j]) for j in range(y[i]): l5.append(int(l4[j])) print(sum(l5))
l1=[6,2,4,3] l2=[6,6,1,4,7,1] l3=[] for i in l2: if i not in l1: l1.extend([i]*l2.count(i)) else: if(l1.count(i)<l2.count(i)): l1.extend([i]*(l2.count(i)-l1.count(i))) print(l1) #solution2 from collections import Counter as cs l1=[6,6,2,4,3] l2=[6,1,4,7,1] n1=cs(l1) n2=cs(l2) for i,j in n1.items(): if( i in n2): if n2[i]>j: print((str(i)+' ')*n2[i],end='') else: print((str(i)+' ')*j,end='') else: print((str(i)+' ')*j,end='') for i,j in n2.items(): if(i not in n1): print((str(i)+' ')*j,end='')
from collections import Counter as cs from collections import defaultdict as dc x = input().split(" ") x = list(map(int, x)) for i in range(len(x)): l1 = [] d = dc() for j in range(x[i]): y = input() d[j + 1] = y l1.append(y) print(l1) print(d) print(cs(l1)) a = cs(l1) for k, v in a.items(): if v != 1: for i in d.keys(): if d[i] == k: print(i, end="") print() '''5 2 a b a a b ['a', 'b', 'a', 'a', 'b'] defaultdict(None, {1: 'a', 2: 'b', 3: 'a', 4: 'a', 5: 'b'}) Counter({'a': 3, 'b': 2})
from collections import Counter as cs,defaultdict as dd,OrderedDict x=cs(list(input())) d=dd() x=(OrderedDict(sorted(x.items(),key=lambda kv:kv[1] ,reverse=True))) for k,v in x.items(): if v>1: print(k,v)