Use scipy — it's great
Code\n\nfrom scipy.sparse.csgraph import connected_components as cc\nfrom numpy import array as arr\n\n\nclass Solution:\n    def findCircleNum(self, isConnecte
# Code\n```\nfrom scipy.sparse.csgraph import connected_components as cc\nfrom numpy import array as arr\n\n\nclass Solution:\n    def findCircleNum(self, isConnected: List[List[int]]) -> int:\n        return cc(arr(isConnected))[0]\n```
['Python3']