0

I have a list of dictionaries looking like this:

[{'customer': 'Charles', 'city': 'Paris'}, {'customer': 'John', 'city': 'New York'}, {'customer': 'Jean', 'city': 'Paris'}]

I tried something using collections which will return me the name of the most common city in this list of dictionaries:

city_counts = Counter(c['city'] for c in customers)
return city_counts .most_common(1)[0][0]

From this, I would like to return a list of all customers who are not in this city. So, if I take the list I gave above, ['John'] should be the output.

I there a best way to do it ?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Synops
  • 122
  • 3
  • 11

0 Answers0