associative list python
Question: i am parsing some html form with Beautiful soup. Basically i´ve around 60
input fields mostly radio buttons and checkboxes. So far this works with the
following code:

    
    
    from BeautifulSoup import BeautifulSoup
    x = open('myfile.html','r').read()
    out = open('outfile.csv','w')
    soup = BeautifulSoup(x)
    values = soup.findAll('input',checked="checked")
    # echoes some output like ('name',1) and ('value',4)
    
    for cell in values:
    # the following line is my problem! 
        statement = cell.attrs[0][1] + ';' + cell.attrs[1][1] + ';\r'
        out.write(statement)
    
    out.close()
    x.close()
    

As indicating in the code my problem ist where the attributes are selected,
because the HTML template is ugly, mixing up the sequence of arguments that
belong to a input field. I am interested in name="somenumber"
value="someothernumber" . Unfortunately my attrs[1] approach does not work,
since name and value do not occur in the same sequence in my html.

Is there any way to access the resulting BeautifulSoup list associatively?

Thx in advance for any suggestions!


Answer: I'm fairly sure you can use the attribute name like a key for a hash:

    
    
    print cell['name']
    

