[Python3] count properly
Algo\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\nImplementation
**Algo**\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\n**Implementation**\n```\nclass Solution:\n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n        m = len(languages)\n        languages = [set(x) for x in languages]\n        \n        mp = {}\n        for u, v in friendships: \n            if not languages[u-1] & languages[v-1]: \n                for i in range(n):\n                    if i+1 not in languages[u-1]: mp.setdefault(u-1, set()).add(i)\n                    if i+1 not in languages[v-1]: mp.setdefault(v-1, set()).add(i)\n        \n        ans = inf\n        for i in range(n): \n            val = 0\n            for k in range(m): \n                if i in mp.get(k, set()): val += 1\n            ans = min(ans, val)\n        return ans \n```\n\n**Analysis**\nTime complexity `O(MN)`\nSpace complexity `O(M+N)`\n\nEdited on 2/10/2021\nA clearner implementation is given below \n```\nclass Solution:\n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n        languages = [set(x) for x in languages]\n        \n        users = set()\n        for u, v in friendships: \n            if not languages[u-1] & languages[v-1]: \n                users.add(u-1)\n                users.add(v-1)\n        \n        freq = {}\n        for i in users: \n            for k in languages[i]:\n                freq[k] = 1 + freq.get(k, 0)\n        return len(users) - max(freq.values(), default=0)\n```
['Python3']