views:

47

answers:

1

The Dictionary is as given below:

goodDay= {'Class':[1,1,0,0,0,1,0,1,0,1], 'Grade':[1,0,0,1,0,1,0,1,0,1]} 

I want to code this way that i should get the count of "1" and also "0" in Class when my grade has value "1" and also vice versa i.e. when my grade has value "0". So i will have to traverse through the list values for both and Class and Grade and then may be put this condition while segregating. Please help. Thanks

+1  A: 

This counts the number of cs (classes) which are 1 when g (grades) is 1:

In [5]: sum(c for c,g in zip(goodDay['Class'],goodDay['Grade']) if g)
Out[5]: 4

And this gives the number of gs that are 1 when c is 1:

In [6]: sum(g for c,g in zip(goodDay['Class'],goodDay['Grade']) if c)
Out[6]: 4
unutbu
Thaanks for the answer but i did not understand the meaning of In[5] Out [5], In[6] and Out[6]
Compuser7
Those are produced by his python interpreter. Probably ipython.
hughdbrown