mercredi 20 février 2019

Distinguishing Words with other Words within It

so I'm trying to be able to detect only "astro" (case insensitive) in a sentence with other words that contain the word "astro" in it. For example:

message = Astro, the astronaut, studies astrology.

if 'astro' in message:
    count = message.count('astro')
    print(count)

The output of this current code would be 3 because there are three words that contain that word in it, but I want the desired output to be 1; the first word. Any help would be greatly appreciated, thanks!

Aucun commentaire:

Enregistrer un commentaire