aboutsummaryrefslogtreecommitdiff
path: root/challenge-272/pokgopun/python/ch-1.py
blob: 2b328144e9c5b25df5776c102b38d82b4f1d1ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
### https://theweeklychallenge.org/blog/perl-weekly-challenge-272/
"""

Task 1: Defang IP Address

Submitted by: [45]Mohammad Sajid Anwar
     __________________________________________________________________

   You are given a valid IPv4 address.

   Write a script to return the defanged version of the given IP address.

     A defanged IP address replaces every period “.” with “[.]".

Example 1

Input: $ip = "1.1.1.1"
Output: "1[.]1[.]1[.]1"

Example 2

Input: $ip = "255.101.1.0"
Output: "255[.]101[.]1[.]0"

Task 2: String Score
"""
### solution by pokgopun@gmail.com

def dfip(string: str):
    return string.replace(".","[.]")

import unittest

class TestDfip (unittest.TestCase):
    def test(self):
        for inpt, otpt in {
                "1.1.1.1": "1[.]1[.]1[.]1",
                "255.101.1.0": "255[.]101[.]1[.]0",
                }.items():
            self.assertEqual(dfip(inpt),otpt)

unittest.main()