Problem

Description

Write a function to split a string and convert it to an array of words.

Test Cases

string_to_array("Python is the best!") # returns ["Python", "is", "the", "best"]

Solution

My Solution

def string_to_array(s):
    return s.split() if s!= '' else ['']

Other Solutions

def string_to_array(string):
    return string.split(" ")

Learning Experiences

  • Python lets you specify the delimiter, i.e what the text is being split by! This ensures that only gaps between words are being split.