How to sort Counter by value? – python

Use the Counter.most_common() method, it’ll sort the items for you: >>> from collections import Counter >>> x = Counter({‘a’:5, ‘b’:3, ‘c’:7}) >>> x.most_common() [(‘c’, 7), (‘a’, 5), (‘b’, 3)] It’ll do so in the most efficient manner possible; if you ask for a Top N instead of all values, a heapq is used instead of … Read more

Hot to get the loop counter/index using for…of syntax in JavaScript

for…in iterates over property names, not values, and does so in an unspecified order (yes, even after ES6). You shouldn’t use it to iterate over arrays. For them, there’s ES5’s forEach method that passes both the value and the index to the function you give it: var myArray = [123, 15, 187, 32]; myArray.forEach(function (value, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)