vendredi 23 septembre 2016

Python need help to print multiple occurrences in a string

I'm trying to write a function where the input has a key word that occurs multiple times in a string and will print the stuff that has double quotation marks between them after the key word. Essentially...

Input= 'alkfjjiekeyword "someonehelpmepls"fjioee... omgsos someonerandom help helpppmeeeeeee keyword"itonlygivesmeoneinsteadofmultiple... sadnesssadness!sadness'

Output= someonehelpmepls

itonlygivesmeoneinsteadofmultiple

And I'm not sure if its possible to have the outputs as its own line but that would be better if possible please :)

Here's what I have so far:

def getEm(s): 

    h = s.find('keyword') 

    if h == -1 
       return -1 

    else: 
       begin = s.find('"',h) 
       end = s.find('"', begin+1) 
       result = s[begin +1:end] 
    print (result)

Any advice? Also please don't suggest import. I do not know how to do that or actually know what it is, I am a beginner.

Aucun commentaire:

Enregistrer un commentaire