DEV Community

Discussion on: 30 Days of Python 👨‍💻 - Day 6 - Loops II & Functions

Collapse
 
arindamdawn profile image
Arindam Dawn

Nice try :) but as Adrian suggested it is not recommended to use dunder methods unless you are planning to override some built-in utility function in a class.

Let me provide an alternate one-line solution using comprehensions which I discovered lately :)

email_list = ['roger@hey.com','michael@hey.com','roger@hey.com','prince@gmail.com']
duplicates = list(set([email for email in email_list if email_list.count(email) > 1 ]))

print(duplicates)

Comprehensions look way cool but they can impact the code readability.

Collapse
 
matteodellirocioli profile image
MatteoDelliRocioli • Edited

Very interesting indeed!

Noice