Skip to content

Incorrect canonical solution #26

Description

@feixiangdejiahao

Mbpp/748

def capital_words_spaces(str1: str) -> str:
"""
Write a function to put spaces between words starting with capital letters in a given string.
assert capital_words_spaces("Python") == 'Python'
"""

Corresponding canonical solution

import re
def capital_words_spaces(str1):
  return re.sub(r"(\w)([A-Z])", r"\1 \2", str1)

Hidden test:

Input:
MyNameIsAIAndIAmHereToHelpYou

Output:
My Name Is AI And IAm Here To Help You'

gpt-4o generated program:

import re
def capital_words_spaces(str1: str) -> str:
    return re.sub('(?<!^)(?=[A-Z])', ' ', str1)

Corresponding output: My Name Is A I And I Am Here To Help You

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions