Python find the frequency of combinations in 2 lists -


i have 2 lists,

list1 = ['a', 'b', 'c', 'a'] list2 = ['a', 'b', 'c', 'd','a'] 

how can find frequency each combinations of 'a''a', 'b''b' , 'c''c' ?

use aptly named counter, collections, this:

>>> collections import counter >>> counter(zip(['a','b','c','a'],['a','b','c','a'])).most_common() [(('a', 'a'), 2), (('b', 'b'), 1), (('c', 'c'), 1)] 

zip creates pairs of objects should compared:

>>> zip(['a','b','c','a'],['a','b','c','a']) [('a', 'a'), ('b', 'b'), ('c', 'c'), ('a', 'a')] 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -