Sort python list by function
sort(my_list_of_objects, key=my_number_giving_function) same for sorted, see the Python Sorting HOWTO
sort(my_list_of_objects, key=my_number_giving_function) same for sorted, see the Python Sorting HOWTO
Check if you could go with any of the below mentioned JQuery plugins. Simply awesome and provide wide range of options to work through, and less pains to integrate. 🙂 https://github.com/paulopmx/Flexigrid – Flexgrid http://datatables.net/index – Data tables. https://github.com/tonytomov/jqGrid If not, you need to have a link to those table headers that calls a server-side script … Read more
There’s a method on the DataGridView called “Sort”: this.dataGridView1.Sort(this.dataGridView1.Columns[“Name”], ListSortDirection.Ascending); This will programmatically sort your datagridview.
Using uksort: uksort($array, function($a, $b) { return count($b) – count($a); }); Using array_multisort: array_multisort(array_map(‘count’, $array), SORT_DESC, $array); With PHP < 5.3: function sort_cb($a, $b) { return count($b) – count($a); } uksort($array, ‘sort_cb’);
The first improvement would be to simplify the three cases in the main loop: Rather than iterating while some of the sequence has elements, iterate while both sequences have elements. When leaving the loop, one of them will be empty, we don’t know which, but we don’t care: We append them at the end of … Read more
You can split the prop on ., and iterate over the Array updating the a and b with the next nested property during each iteration. Example: http://jsfiddle.net/x8KD6/1/ var sort = function (prop, arr) { prop = prop.split(‘.’); var len = prop.length; arr.sort(function (a, b) { var i = 0; while( i < len ) { … Read more
Use LINQ OrderByDescending method. It returns IOrderedIEnumerable<int>, which you can convert back to Array if you need so. Generally, List<>s are more functional then Arrays. array = array.OrderByDescending(c => c).ToArray();
In your example a.sort is equivalent to a.sort { |x, y| x <=> y } As you know, to sort an array, you need to be able to compare its elements (if you doubt that, just try to implement any sort algorithm without using any comparison, no <, >, <= or >=). The block you … Read more
On windows the CTime is the creation time, use the following: <?php $files = array(); foreach (new DirectoryIterator(‘/path’) as $fileInfo) { $files[$fileInfo->getFileName()] = $fileInfo->getCTime(); } arsort($files); After this $files will contain an array of your filenames as the keys and the ctime as the values. I chose this backwards representation due to the possibility of … Read more
The sorted() function takes a key= parameter newlist = sorted(list_to_be_sorted, key=lambda d: d[‘name’]) Alternatively, you can use operator.itemgetter instead of defining the function yourself from operator import itemgetter newlist = sorted(list_to_be_sorted, key=itemgetter(‘name’)) For completeness, add reverse=True to sort in descending order newlist = sorted(list_to_be_sorted, key=itemgetter(‘name’), reverse=True)