Print part of String with matching Index
<p>I'm trying to make a Program that takes a given text, checks to see at which indexes (") is located throughout the text and prints anything in-between the quotation marks (") i.e. "xyz" blablabla "abc". In this case, xyz between 0 and 4 and abc between 16 and 20 would be printed. I've got the indexes part to work but can't seem to find a way to print whatever's within the range of these indexes. Here's my code:</p>

<pre><code>text = '"bleed" seed "deed"'

index = 0

a = 0

find = int(input("Would you like to find all the links in the file?\n If yes, enter 1:  "))

def Link_Finder(a):

    index = 0

    if find == 1:

        while index &lt; len(text):

            index = text.find('"', index)

            if index == -1:

                break


            print('" found at', index)


            index = index + 2

    return index

Link_Finder(a)

print(text[index:])
</code></pre>

<p>I'm only printing the Indexes for my own reference. I'm quite new to Python so I'm not really familiar with complex stuff yet.</p>

<p>One way to do this in my opinion would be to return the Index values and then use the returned values to print the required text.</p>

<p>Thanks.</p>

<p>If you don't mind using regular expressions, I think this is an easier solution:</p>

<pre><code>import re
print(re.findall(r'"([^"]*)"', text))
</code></pre>

<p>If not, you can use your <code>link_finder</code> function:</p>

<pre><code>def link_finder(s):
    index = 0
    while index &lt; len(s):
        index = s.find('"', index)
        if index == -1:
            break
        yield index
        index = index + 2
</code></pre>

<p>And then iterate through the results in pairs</p>

<pre><code>results = list(link_finder(text))

for start, end in zip(results[::2], results[1::2]):
    print text[start+1:end]
</code></pre>

python python-3.x