How can I split and give uppercase to a string at the same time?

Question:

I have this string, I am fairly new to python and I just need help doing this.

def this_sentence(My friend went on a tour)

I want the Output to look like this
[‘MY’, ‘FRIEND’, ‘WENT’, ‘ON’, ‘A’, ‘TOUR’]

Asked By: Barkley

||

Answers:

You don’t even need a separate function, just use split() and upper():

split_sentence = [word.upper() for word in sentence.split()]
Answered By: B Remmelzwaal

You can use str.upper() to make all characters uppercase and then str.split() to split the words at each space.

def this_sentence(sentence):
    return sentence.upper().split()
Answered By: Juan Melnechuk
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.