I'm very new to python. This question might be very simple. I have two lists as below;
Mobile= ('M1','M1','M1','M1','M1','M1','M1','M2','M2','M2','M2','M2','M2','M2')
Test=('call','call','sms','sms','mms','call','call','mms','mms','sms','sms','voltecall','voltecall','voltecall')
I want to write a loop to count how many times each Test item is done for each value in Mobile. For example I want the code to tell me 'M1' had Four 'call' scenarios, Two 'sms' and one 'mms'. I thought I could do this in dictionary so I created a tot variable to use as a key in dictionary and created the dictionary (as below) but i'm not sure how to use for and if statements to do what I want. The code I wrote below is not giving the correct answer. It just returns zero.
Mobile= ('M1','M1','M1','M1','M1','M1','M1','M2','M2','M2','M2','M2','M2','M2')
Test=('call','call','sms','sms','mms','call','call','mms','mms','sms','sms','voltecall','voltecall','voltecall')
tot=(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
a_dict=dict(zip(tot,zip(Mobile,Test)))
for k, v in a_dict.iteritems():
if (k==Mobile[1] and v==Test[1]):
countM1Test1+=1
Aucun commentaire:
Enregistrer un commentaire