How save an string output after a for loop in python with pandas and csv modules?
<p>I have the following for loop:</p>

<pre><code>    for titles in titles:
        title = titles.xpath("a/text()").extract()
        link = titles.xpath("a/@href").extract()
        print(title, link)
</code></pre>

<p>How can I dump the title and link into a formmated .csv file?</p>

<pre><code>result = []
for titles in titles:
    title = titles.xpath("a/text()").extract()
    link = titles.xpath("a/@href").extract()
    print(title, link)
    result += [title + ',' + link + '\n']

with open("result.csv" "w+") as f:
    f.writelines(result)
</code></pre>

python python-3.x csv pandas