def isAnagram(self, s: str, t: str) -> bool:
     from _collections import Counter
     s = Counter(s)
     t = Counter(t)
     if s == t:
         return True
     else:
         return False
 def intersect(self, nums1: list[int], nums2: list[int]) -> list[int]:
     from _collections import Counter
     nums1_dict = Counter(nums1)
     res = []
     for num in nums2:
         if nums1_dict[num] > 0:
             res.append(num)
             nums1_dict[num] -= 1
     return res
Beispiel #3
0
    def mode(data):
        n = len(data)
        num = Counter(data)
        get_mode = dict(data)
        mode = [k for k, v in get_mode.items() if v == max(list(num.values()))]

        if len(mode) == n:
            return -1
        else:
            get_mode = int(''.join(map(str, mode)))
        return get_mode
Beispiel #4
0
p = list(map(str, input().split()))
c = list(map(str, input().split()))

from _collections import Counter

Counter(p, )
Beispiel #5
0
def isAnagram(self, s: str, t: str) -> bool:
    a = Counter(s)
    b = Counter(t)
    if a == b:
        return True
    return False
Beispiel #6
0
def mode(target):
    return Counter(target).most_common(1)[0][0]
Beispiel #7
0
print(d)

#####################################################################
from _collections import ChainMap

a = {1: 'Mahesh', 2: 'Python'}
a = {1: 'Neha', 2: 'GoLang'}

c = ChainMap(a, b)
print(c)

#####################################################################
from _collections import Counter

a = [1, 2, 3, 4, 5, 6, 12, 3, 2, 1, 3, 5, 6, 2, 1, 1, 13, 2]
cnt = Counter(a)  #counts no. of elements
print(cnt)
print(list(cnt.elements()))  #print sorted list
print(c.most_common())

#####################################################################
from _collections import OrderedDict

o = OrderedDict()
o[1] = 'm'
o[2] = 'a'
o[3] = 'h'
o[4] = 'e'
o[5] = 's'
o[6] = 'h'