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 previous articles, so there you go :)
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.
You should use len(email_list) instead of _ _ len() _ _ (excuse the spaces, the text goes bold if I leave them out). The _ _ method is really an internal method len() looks for on a class. There are lots of them, actually check out the special methods section the docs for info.
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 previous articles, so there you go :)
What do you guys think about it?
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 :)
Comprehensions look way cool but they can impact the code readability.
Very interesting indeed!
You should use len(email_list) instead of _ _ len() _ _ (excuse the spaces, the text goes bold if I leave them out). The _ _ method is really an internal method len() looks for on a class. There are lots of them, actually check out the special methods section the docs for info.
Thanks for the hint! 😄