Capitalize!

Sort by

recency

|

2798 Discussions

|

  • + 0 comments

    solution in one line:

    def solve(s):
        return " ".join(list(map(lambda x: x.capitalize(), s.split(" "))))
    
  • + 0 comments
    def solve(s):
        name = ''
        while len(s):
            position = re.search(r'\S+ *', s)
            word = position.group()
            word = word[0].upper() + word[1:]
            name = name + word
            s = s[len(position.group()): ]
    return name
    
  • + 0 comments

    def solve(s): name = s.split(" ") #print(name) #print(len(name))

    for i in range(len(name)):
        name[i] = name[i].capitalize()
    return " ".join(name)
    
  • + 1 comment

    Easiest solution without any inbuilt functions

    def solve(s):
        new_word = ""
        word_start = True  # To track the start of a new word
    
        for char in s:
            if char != " " and word_start:  # If it's a non-space and start of a word
                if 'a' <= char <= 'z':  # Check if char is a lowercase letter
                    new_word += char.upper()  # Convert to uppercase
                else:
                    new_word += char  # Keep the character unchanged
                word_start = False  # Set flag to False after first letter
            else:
                new_word += char     
            if char == " ":  # Reset flag when encountering a space
                word_start = True  
    
        return new_word
    
  • + 0 comments

    def solve(s): res="" is_new_word=True for char in s: if char == " ": res+=char is_new_word=True elif(is_new_word): if char.isalpha(): res+=char.upper() is_new_word=False else: res+=char is_new_word=False else: res+=char return res