Skip to content

Latest commit

 

History

History
41 lines (22 loc) · 567 Bytes

File metadata and controls

41 lines (22 loc) · 567 Bytes

CodeWars Python Solutions


Convert a string to an array

Write a function to split a string and convert it into an array of words. For example:

"Robin Singh" ==> ["Robin", "Singh"]

"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]

Given Code

def string_to_array(s):
    pass

Solution

def string_to_array(s):
    return s.split() if len(s) > 0 else [""]

See on CodeWars.com