Click here to Skip to main content
16,005,389 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
return [
    x for x in nums
    if x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]
  ] 


What I have tried:

<pre>
for x in nums:
for n in nums:
if x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]

return x
Posted
Updated 28-Oct-21 5:07am
v2
Comments
Richard MacCutchan 28-Oct-21 4:26am    
Separate each part out of the statement and run it in the Python ide and you will see.

1 solution

As mentioned in my comment run the following in order in a Python shell or IDE:
Python
Counter([n % 2 for n in nums]) # returns the counts of odd and even numbers
Counter([n % 2 for n in nums]).most_common() # as above but ordered by count descending
Counter([n % 2 for n in nums]).most_common()[0] # the set with the most entries (odd numbers or evens)
Counter([n % 2 for n in nums]).most_common()[0][0] # 1 or 0 depending on which are most common.

as for the rest, you need to find out what it is supposed to be doing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900