Remove duplicates from list and order it by count? (python 3) How do I remove all duplicates from list and order it based on count?
s = [&quot;foo&quot;, &quot;this&quot;, &quot;lem&quot;, &quot;foo&quot;, &quot;lem&quot;]
s = [&quot;foo&quot;, &quot;ebh&quot;, &quot;wosv&quot;, &quot;wosv&quot;, &quot;ebh&quot;, &quot;4whcu&quot;]
#should return
&gt;&gt;&gt; [&quot;foo&quot;, &quot;lem&quot;, &quot;this&quot;]
&gt;&gt;&gt; [&quot;ebh&quot;, &quot;wosv&quot;, &quot;foo&quot;, &quot;4whcu&quot;]

Rules:

Must be shorter than the below code in terms of byte size.
Order must be based on the count of  in descending order.
If there are two strings with the same count, the first appearance comes first
All duplicates must be removed, only one of each string should be in the final list

I currently have
list({}.fromkeys(sorted(s,key=lambda y:-s.count(y))))

I've noticed answers like set but that arbitrarily changes the order, which I do not want.
Edit: Sorry for the poor quality before. I had whipped this right before I slept and I was quite tired. This is not for StackOverflow because I'm trying to golf/shorten the size of this code as much as possible. I've tried looking for answers but I haven't been able to find anything.
44 bytes

sorted({}.fromkeys(s),key=s.count,reverse=1)

Try it online!
An improvement to the below, replacing the key with a built-in rather than a lambda, and using reverse to swap the comparisons. We'd like to do [::-1] on the final result instead, but that doesn't do the right stable tiebreaks.

47 bytes

sorted({}.fromkeys(s),key=lambda y:-s.count(y))

Try it online!
A simple transposition of your code, moving your {}.fromkeys de-duplication trick before the sorting. Since sorting converts to a list, extracting the keys from a dictionary, this saves the list() call of the original.
For ease of reference, the original code is:
53 bytes

list({}.fromkeys(sorted(s,key=lambda y:-s.count(y))))

Try it online!