how to count the total number of items for the lists contain a specific item in python -


i want count total items lists contain 'a', should 4+3 = 7

tweetword = (['a','b','c','a'],['a','e','f'],['d','g']) count_total_a = {} t in tweetword:     word in tweetword:         if word not in count_total_a:             count_toal_a[word] = len(t)         if word in count_total_a:             count_total_a[word] += len(t) '''the result not correct coz counts first list twice''' 

really appreciate help!

take sum on generator:

sum(len(x) x in tweetword if 'a' in x) 

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 -