Python: How to use an item from a python list which appears a specific number of times? -


suppose have python list num = [1,2,5,3,4,4] , know there item appears 2 times in num. want use item. there predefined function choose item?

*there no upper limit on value of items in num.

there no predefined function, no. you'll have count items , figure out 1 can found twice in list.

you can use collections.counter() object counts, , there reasonably easy enumerate values appear twice:

from collections import counter  counts = counter(num) twice = [n n, count in counts.iteritems() if count == 2] 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -