操作 sets
在製作你的食譜等比例調整工具時,你決定把多個食譜合併成一份採買清單。你已經把所有食材收集在名為 all_ingredients 的列表中。由於相同的食材會出現在不同食譜裡,清單中會有重複的名稱。你想建立一個 set,來確定實際需要購買的獨特食材數量。all_ingredients 列表已經幫你建立好了。
本練習屬於課程
Python 入門(開發者向)
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Convert the all_ingredients list to a set
unique_ingredients = ____
print(unique_ingredients)