Hackerrank string capitalize problem Python

  python, python-3.x

my code failed 4/6 test cases for the below problem,
https://www.hackerrank.com/challenges/capitalize/problem

Here is my code:

def solve(s):
    s = s.split()
    return ' '.join([i.capitalize() for i in s])

correct solution should be:

    return ' '.join(map(str.capitalize, string.split(' ')))

As a python newbie, I understand what map function does in the correct solution but I can’t see why my code failed few cases. Anyone can give me a hand, please?

Source: Python Questions

LEAVE A COMMENT