Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Create list

  • Create a script called create_list.py that given a list of strings with words separated by spaces, create a single list of all the words.

  • Skeleton:

lines = [
    'grape banana mango',
    'nut orange peach',
    'apple nut banana apple mango',
]

# ....

print(fruits)

# ....

print(unique_fruites)
  • Expected result:
['grape', 'banana', 'mango', 'nut', 'orange', 'peach', 'apple', 'nut', 'banana', 'apple', 'mango']

Then create a list of unique values sorted in alphabetical order.

Expected result:

['apple', 'banana', 'grape', 'mango', 'nut', 'orange', 'peach']