samedi 4 juillet 2020

How to use Split function and If-Else to split a sentence into 2 lists based on key words

I'm new to coding in Python. I want to split the sentence in the Sample_text into 2 different lists, based on whether the word is a fruit or a non-fruit word, using an if-else loop.

Sample_text = """Blend mangos puree, almond milk, protein powder, peanut butter, and strawberries in a blender until smooth. Serve immediately."""

fruits = ["bannanas","acai","blueberries","strawberries","mangos"]

fruit_words = []
non_fruit_words = []
for word in Sample_text.split(" "):
      if 
      else

Aucun commentaire:

Enregistrer un commentaire