Split the Phone Numbers

  • + 3 comments

    I know this isn't strictly a Python problem, however, it is a good simple problem to test or remind yourself of how to use Python decorators.

    Without revealing the RegEx I used, the following is what I did to decorate the basic PhoneNumber() function, which simply extracts the groups.

    def Wrapper(func):
        def Decorate(Num):
            Num = func(Num)
            return "CountryCode=%s,LocalAreaCode=%s,Number=%s" % Num
        return Decorate
    
    @Wrapper
    def PhoneNumber(Num):
        return re.match(RegEx,Num).groups();
    
    for _ in range(int(input())):
        print(PhoneNumber(input().strip()))