illustrated explanation
<<--please vote\n\n\n\n\n    def regionsBySlashes1(self, grid):\n        parent = {}\n        find = lambda x: x if x == parent.setdefault(x, x) else find(paren
<<--please vote\n\n![image](https://assets.leetcode.com/users/images/03c2ab22-3e52-4f1d-abf1-ccc8bfde7e39_1646315387.335891.png)\n\n\n    def regionsBySlashes1(self, grid):\n        parent = {}\n        find = lambda x: x if x == parent.setdefault(x, x) else find(parent[x])\n        union = lambda x, y: (x := find(x), y := find(y)) and parent.__setitem__(x, y)\n\n        for y, row in enumerate(grid):\n            for x, val in enumerate(row):\n                y and union((y - 1, x, \'D\'), (y, x, \'U\'))\n                x and union((y, x - 1, \'R\'), (y, x, \'L\'))\n                val != "/" and (union((y, x, \'U\'), (y, x, \'R\')), union((y, x, \'D\'), (y, x, \'L\')))\n                val != "\\\\" and (union((y, x, \'L\'), (y, x, \'U\')), union((y, x, \'R\'), (y, x, \'D\')))\n        return len(set(map(find, parent)))\n\nunion-find explanation\n\n![image](https://assets.leetcode.com/users/images/5cf11fbc-b358-4e54-8ca1-63326a7e766b_1646311072.7900712.png)\n\n![image](https://assets.leetcode.com/users/images/032a7659-80fe-4c63-a67d-2510394085a0_1646311076.6620572.png)
['Union Find', 'Python']