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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -