Camel Case 4

  • + 1 comment

    Hi everyone! Here’s my solution to this exercise. I’m currently having an issue with Test Case 2. When I run the code, it seems to produce the expected result, but it’s still not passing. Does anyone have an idea of what might be going on?

    import re
    import sys
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    def split_word(word):
        word = re.sub(r'\(\)$', r'', word)        
        word = re.sub(r'(?<!^)([A-Z])', r' \1', word)
        word = word.lower()
        print(word)
        
        
    def combine_word(word, word_type):
        word = word.strip()
        if word_type == 'M':
            word = word + "()"
        elif word_type == 'C':
            word = word.capitalize()
        word = re.sub(r'\s([a-z])', lambda x: x.group(1).upper(), word)
                
        print(word)
    
    
    def camelCase(action, word_type, word):
        if action == 'S':
            split_word(word)
        elif action == 'C':
            combine_word(word, word_type)
    
    input_lines = sys.stdin.read().strip().split('\n')
    for line in input_lines:
        action, word_type, word = line.split(';')
        camelCase(action, word_type, word)