loading...

re: 30 Days of Python 👨‍💻 - Day 6 - Loops II & Functions VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hey, I came up with this odd solution. It's obviously not as clean as yours but I'm trying to apply some concepts you have explained in the previou...
 

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.

 
code of conduct - report abuse