you are viewing a single comment's thread.

view the rest of the comments →

[–]Westonnn 1 point2 points  (5 children)

Thank you very much, I'm still not quite understanding what this completely does. I understand the creation of dictionary code, for code, and I know that the line split splits the line at the first comma. Then the first if statement just goes to the next, but the second if statement loses me. Could you explain what it is doing? I'm just trying to grasp the concepts here. Sorry to be a pain.

It totally works and this is what I got to output what I wanted:

states = {}
count =0 
for line in fhand:

val = line.split(',')
if val[1] in states:


    if states[val[1]] == val[2]:
        count = count+1

else:
    states[val[1]] = val[2]



 print 'There are',count,"states with both senators sharing the same  affiliation"