Suppose we have a valid IPv4 IP address. We have to return the Defanged version of the IP address. A Defanged IP address is basically replace every period “.” by “[.]” So if the IP address is “192.168.4.1”, the output will be “192[.]168[.]4[.]1”
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution(object): def defangIPaddr(self, address): address = address.split(".") return "[.]".join(address) ob1 = Solution() print(ob1.defangIPaddr("192.168.4.1"))
"192.168.4.1"
"192[.]168[.]4[.]1"