sorting

Python sorting list with negative number

倖福魔咒の 提交于 2020-12-09 11:16:09
问题 In attempt to learn python by practicing, I am trying to implement and test out quick sort algorithm using python. The implementation itself was not difficult, however the result of the sort is somewhat puzzling: When I sort a list ['35', '-1', '-2', '-7', '-8', '-3', '-4', '20', '-6', '53'] the result gives me ['-1', '-2', '-3', '-4', '-6', '-7', '-8', '20', '35', '53'] So the list is sorted however the negative integers are sorted in reverse order. I suspect this may be the problem with the

Language dependent sorting with R

情到浓时终转凉″ 提交于 2020-12-09 09:59:09
问题 1) How to sort correctly? The task is to sort abbreviated US states names in accordance with English alphabet. But I noticed, that R sorts lists basing on some kind of operating system language or regional settings. E.g., in my language (Lithuanian) even the order of Latin (non-Lithuanian) letters differs from the order in the English alphabet. Compare order of non-Lithuanian letters only in both alphabets: "ABCDEFGHI Y JKLMNOPRSTUVZ" sort(LETTERS) [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "Y"

Language dependent sorting with R

人走茶凉 提交于 2020-12-09 09:54:02
问题 1) How to sort correctly? The task is to sort abbreviated US states names in accordance with English alphabet. But I noticed, that R sorts lists basing on some kind of operating system language or regional settings. E.g., in my language (Lithuanian) even the order of Latin (non-Lithuanian) letters differs from the order in the English alphabet. Compare order of non-Lithuanian letters only in both alphabets: "ABCDEFGHI Y JKLMNOPRSTUVZ" sort(LETTERS) [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "Y"

How to group by one column and sort the values of another column?

让人想犯罪 __ 提交于 2020-12-08 11:47:30
问题 Here is my dataframe import pandas as pd df = pd.DataFrame({'A': ['one', 'one', 'two', 'two', 'one'] , 'B': ['Ar', 'Br', 'Cr', 'Ar','Ar'] , 'C': ['12/15/2011', '11/11/2001', '08/30/2015', '07/3/1999','03/03/2000' ], 'D':[1,7,3,4,5]}) My goal is to group by column A and sort within grouped results by column B . Here is what I came up with: sort_group = df.sort_values('B').groupby('A') I was hoping that grouping operation would not distort order, but it does not work and also returns not a

How to group by one column and sort the values of another column?

白昼怎懂夜的黑 提交于 2020-12-08 11:28:17
问题 Here is my dataframe import pandas as pd df = pd.DataFrame({'A': ['one', 'one', 'two', 'two', 'one'] , 'B': ['Ar', 'Br', 'Cr', 'Ar','Ar'] , 'C': ['12/15/2011', '11/11/2001', '08/30/2015', '07/3/1999','03/03/2000' ], 'D':[1,7,3,4,5]}) My goal is to group by column A and sort within grouped results by column B . Here is what I came up with: sort_group = df.sort_values('B').groupby('A') I was hoping that grouping operation would not distort order, but it does not work and also returns not a

Worst case of the Quicksort algorithm

天涯浪子 提交于 2020-12-08 06:44:20
问题 I found many implementations of quick sort algorithm, but at the end I decided to stick to this one: public static void quickSort(int array[], int start, int end) { if(end <= start || start >= end) { } else { int pivot = array[start]; int temp = 0 ; int i = start+1; for(int j = 1; j <= end; j++) { if(pivot > array[j]) { temp = array[j]; array[j] = array[i]; array[i] = temp; i++; } } array[start] = array[i-1]; array[i-1] = pivot; quickSort(array, start, i-2); quickSort(array, i, end); }} There

Worst case of the Quicksort algorithm

核能气质少年 提交于 2020-12-08 06:41:56
问题 I found many implementations of quick sort algorithm, but at the end I decided to stick to this one: public static void quickSort(int array[], int start, int end) { if(end <= start || start >= end) { } else { int pivot = array[start]; int temp = 0 ; int i = start+1; for(int j = 1; j <= end; j++) { if(pivot > array[j]) { temp = array[j]; array[j] = array[i]; array[i] = temp; i++; } } array[start] = array[i-1]; array[i-1] = pivot; quickSort(array, start, i-2); quickSort(array, i, end); }} There

Sorting an array of strings by arbitrary numbers of substrings

对着背影说爱祢 提交于 2020-12-06 08:27:51
问题 I'm attempting to modify the OrderedImportsFixer class in php-cs-fixer so I can clean up my files the way I want. What I want is to order my imports in a fashion similar to what you'd see in a filesystem listing, with "directories" listed before "files". So, given this array: $indexes = [ 26 => ["namespace" => "X\\Y\\Zed"], 9 => ["namespace" => "A\\B\\See"], 3 => ["namespace" => "A\\B\\Bee"], 38 => ["namespace" => "A\\B\\C\\Dee"], 51 => ["namespace" => "X\\Wye"], 16 => ["namespace" => "A\\Sea

Sort javascript object based on date keys

筅森魡賤 提交于 2020-12-05 12:12:42
问题 I have a JavaScript object that looks like follows testObj = { 1/10/2015: {}, 2/10/2015: {}, 3/10/2015: {}, 4/10/2015: {}, 29/09/2015: {}, 30/09/2015: {} } Now, I'm trying to sort this such that the dates are arranged by date in increasing order. For that i've done the following const orderedDates = {}; Object.keys(testObj).sort(function(a, b) { return moment(moment(b, 'DD/MM/YYYY') - moment(a, 'DD/MM/YYYY')).format('DD/MM/YYYY'); }).forEach(function(key) { orderedDates[key] = testObj[key]; }

Sort javascript object based on date keys

人盡茶涼 提交于 2020-12-05 12:11:14
问题 I have a JavaScript object that looks like follows testObj = { 1/10/2015: {}, 2/10/2015: {}, 3/10/2015: {}, 4/10/2015: {}, 29/09/2015: {}, 30/09/2015: {} } Now, I'm trying to sort this such that the dates are arranged by date in increasing order. For that i've done the following const orderedDates = {}; Object.keys(testObj).sort(function(a, b) { return moment(moment(b, 'DD/MM/YYYY') - moment(a, 'DD/MM/YYYY')).format('DD/MM/YYYY'); }).forEach(function(key) { orderedDates[key] = testObj[key]; }