instaed of: newlist = [] for word in wordlist: newlist.append(word.upper()) 1

instaed of: newlist = [] for word in wordlist: newlist.append(word.upper())

newlist = map(str.upper, wordlist)

Here is what the above code is Doing:
1. We create a list of words, wordlist.
2. We create a new list, newlist, and assign it the result of calling map() with two arguments:
a. The function str.upper, which is a built-in function that converts a string to uppercase.
b. The list wordlist.
3. The map() function calls str.upper() on each element of wordlist, and returns a new list containing the results.

Similar Posts