Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 5
    Is there any reason you use a list comprehension instead of a generator comprehension? Commented Sep 4, 2014 at 13:08
  • 124
    Indeed, a simple solution, but complexity is squared because each count() parses the list all over again, so don't use for large lists. Commented Feb 10, 2015 at 15:35
  • 4
    @JohnJ, bubble sort is also simple and works. That doesn't mean we should use it! Commented Dec 17, 2015 at 19:51
  • 1
    @watsonic: Your "simple switch" fails to reduce the time complexity from quadratic to squared in the general case. Replacing l with set(l) only reduces the worst-case time complexity and hence does nothing to address the larger-scale efficiency concerns with this answer. It probably wasn't so simple after all. In short, don't do this. Commented Sep 23, 2017 at 7:38
  • 3
    Do not do this. Commented Dec 19, 2019 at 16:42