Creating lists from csv files with rows with different amounts of entries
Question: I have data in a csv file which looks like this:

    
    
    fromaddress, toaddress, timestamp
    sender1@email.com, recipient1@email.com, recipient2@email.com, 8-1-2015
    sender2@email.com, recipient1@email.com, 8-2-2015
    sender3@email.com, recipient1@email.com, recipient2@email.com, recipient3@email.com, recipient4@email.com, 8-3-2015
    sender1@email.com, recipient1@email.com, recipient2@email.com, recipient3@email.com, 8-4-2015
    

Using Python, I would like to produce a txt file that looks like:

    
    
    sender1_email.com, recipient1_email.com
    sender1_email.com, recipient2_email.com
    sender2_email.com, recipient1_email.com
    sender3_email.com, recipient1_email.com
    sender3_email.com, recipient2_email.com
    sender3_email.com, recipient3_email.com
    sender3_email.com, recipient4_email.com
    sender1_email.com, recipient1_email.com
    sender1_email.com, recipient2_email.com
    sender1_email.com, recipient3_email.com
    

Ultimately, I imagine this whole process will take several steps. After
reading in the csv file, I will need to create separate lists for fromaddress
and toaddress (I am ignoring the timestamp column altogether). There is only 1
email address per row in the fromaddress column, however there are any number
of email addresses per row in the toaddress column. I need to duplicate the
fromaddress email address for each toaddress email address listed for each
row. Once this done I need to replace all of the @ symbols with underscore (_)
symbols. Finally, when I write the txt file, I need to add an extra space
between each row so that it is "double-spaced"

I have not gotten very far as I'm a Python newbie and I'm stuck on the first
step. The following code is duplicating the fromaddress for each individual
character in the toaddress column instead of each individual email address. I
also need help with the toaddress list as well. Can anyone help?

    
    
    import csv
    fromaddress = []
    toaddress = []
    
    with open("filename.csv", 'r') as f:
        c = csv.reader(f, delimiter = ",")
        for row in c:
            for item in row[1]:
                fromaddress.append(row[0]);
    
    print(fromaddress)
    

Everyone, thanks for all of your help! I tried all your code but unfortunately
I'm not getting the output I need. Instead of getting this (what I want):

    
    
    sender1_email.com, recipient1_email.com
    sender1_email.com, recipient2_email.com
    sender1_email.com, recipient3_email.com
    sender2_email.com, recipient1_email.com
    sender3_email.com, recipient1_email.com
    sender3_email.com, recipient2_email.com

I'm getting this:

    
    
    sender1_email.com,"recipient1_email.com, recipient2_email.com, recipient3_email.com"
    sender2_email.com,"recipient1_email.com"
    sender3_email.com,"recipient1_email.com, recipient2_email.com"

There is only 1 element in each "fromaddress" row, but there are multiple
elements in each "toaddress" row. Basically, I have to pair each recipient
address with the correct sender address. I think I'm not getting the right
output because of the ( " ) double quotation marks in the csv file to surround
all of the sender addresses in each row.


Answer: 
    for row in c:   
        for item in row[1]:
            fromaddress.append(row[0]);
    

`for item in row[1]` is going to only look at the second element in each row.
If you want to loop over each row, then assign column elements to variables,
you want this:

    
    
    for row in c:   
        fromaddress.append(row[0]);
        toaddress.append(row[1]);
        # etc...
    

