aboutsummaryrefslogtreecommitdiff
path: root/challenge-272/steven-wilson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-272/steven-wilson/python/ch-1.py')
-rw-r--r--challenge-272/steven-wilson/python/ch-1.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-272/steven-wilson/python/ch-1.py b/challenge-272/steven-wilson/python/ch-1.py
new file mode 100644
index 0000000000..145c0306da
--- /dev/null
+++ b/challenge-272/steven-wilson/python/ch-1.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+
+
+def defang_ip_address(address):
+ ''' Given a valid IPv4 address, return the defanged version of the given IP
+ address.
+
+ A defanged IP address replaces every period “.” with “[.]".
+ >>> defang_ip_address('1.1.1.1')
+ '1[.]1[.]1[.]1'
+ >>> defang_ip_address('255.101.1.0')
+ '255[.]101[.]1[.]0'
+ '''
+ return address.replace(".", "[.]")
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)