Python 3.x: How do I sort a list of tuples that has the same second element (count) by string value?
<p>So for example</p>

<pre><code>['John','John','Mike','Mike','Kate','Kate']
</code></pre>

<p>Should return:</p>

<pre><code>[('John', 2), ('Kate', 2), ('Mike', 2)]
</code></pre>

<p>How can I write code so there is order instead of those three pairs just being in random order?</p>

<p>I need to sort the list of tuples by count from biggest to smallest unless there are ties, then I need to sort the times alphabetically.</p>

<p>There are two ways to do this. In the first method, a sorted list is returned. In the second method, the list is sorted in-place.</p>

<pre><code>import operator

# Method 1
a = [('Mike', 2), ('John', 2), ('Kate', 2), ('Arvind', 5)]
print(sorted(a, key = lambda x : (x[0],)))

# Method 2
a = [('Mike', 2), ('John', 2), ('Kate', 2), ('Arvind', 5)]
a.sort(key=operator.itemgetter(0))
print(a)
</code></pre>

python python-3.x