You can use collections.Counter
to do what you have described easily:
from collections import Counter
mylist = ['A','A','B','C','D','E','D']
cnt = Counter(mylist)
print [k for k, v in cnt.iteritems() if v > 1]
# ['A', 'D']
More Related Contents:
- Remove string in python dictionary value
- Searching for IP addresses in a file
- Swapping variable places inside if throws an error
- Export a list of stock prices to excel
- python program doesn’t work
- Text parsing and retrieval
- How to uninstall Python 2.7 on a Mac OS X 10.6.4?
- Skip the headers when editing a csv file using Python
- “OSError: [Errno 1] Operation not permitted” when installing Scrapy in OSX 10.11 (El Capitan) (System Integrity Protection)
- Using multiple Python engines (32Bit/64bit and 2.7/3.5)
- In Python, why is list[] automatically global?
- Login to website using urllib2 – Python 2.7
- Improve Row Append Performance On Pandas DataFrames
- Unable to install Python packages using pip in Ubuntu Linux: InsecurePlatformWarning, SSLError, tlsv1 alert protocol version
- python: deque vs list performance comparison
- How to set proxy authentication (user & password) using Python + Selenium
- How to unzip gz file using Python
- Is it possible to draw a matplotlib boxplot given the percentile values instead of the original inputs?
- ImportError: No module named bz2 for Python 2.7.2
- Converting .jpg images to .png
- Why do list comprehensions write to the loop variable, but generators don’t? [duplicate]
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- I’m trying to use python in powershell
- Can’t create pdf using python PDFKIT Error : ” No wkhtmltopdf executable found:”
- Why do I get “‘str’ object has no attribute ‘read'” when trying to use `json.load` on a string? [duplicate]
- Catching exception in context manager __enter__()
- confused about random_state in decision tree of scikit learn
- Is possible to mapping view with class using mapper in SqlAlchemy?
- Python 2.7 : LookupError: unknown encoding: cp65001 [duplicate]
- How to handle IncompleteRead: in python