Is there array_count_values() analogue for Python 3.x or best way to do this?
<p>Is there array_count_values() analogue or fastest way to do this in Python 3.x</p>

<p>from</p>

<pre><code>d = ["1", "this", "1", "is", "Sparta", "Sparta"]
</code></pre>

<p>to</p>

<pre><code>{
  '1': 2,
  'this': 1,
  'is': 1,
  'Sparta': 2
}
</code></pre>

<p>You can count the occurrence of each element in a list using <code>Counter</code>:</p>

<pre><code>from collections import Counter

l = [1, "this", 1, "is", "Sparta", "Sparta"]
print(Counter(l))
</code></pre>

<p>This prints</p>

<pre><code>Counter({1: 2, 'Sparta': 2, 'this': 1, 'is': 1})
</code></pre>

<p><a href="https://repl.it/DpTq" rel="nofollow">repl.it link</a></p>

python