sorting

Sort list of colors by HSV/HSB

纵饮孤独 提交于 2021-01-28 01:52:59
问题 I am looking to sort a very long list of colors by their HSV/HSB values. I would like to sort them by Hue, then Sat, then Bright. Really all I need is a way to tell if one color comes "before" or "after" based on that order of HSV since I am just going to make a compareTo() in Java and use a TreeSet to do the ordering. In Java, HSV values are all stored as floats. I am terrible at algorithms like these so any help would be appreciated! 回答1: The brute force way: public final class

Excel formula to take values from cell range, sort alphabetically and write as a single string

有些话、适合烂在心里 提交于 2021-01-27 23:10:43
问题 I currently have a list of translators and the languages they can speak: | A | B | C | D | F | +-------+------------+------------+------------+---------------------------+ 1 | Name | Language 1 | Language 2 | Language 3 | Combined | +=======+============+============+============+===========================+ 2 | John | English | Chinese | Spanish | English, Chinese, Spanish | 3 | Wendy | Chinese | French | English | Chinese, French, English | 4 | Peter | Spanish | Chinese | English | Spanish,

Sorting list of lists by their first element in scheme

北城以北 提交于 2021-01-27 21:22:52
问题 I'm working on sorting a list of lists by their first element for example (sort (list '(2 1 6 7) '(4 3 1 2 4 5) '(1 1)))) expected output => ('(1 1) '(2 1 6 7) '(4 3 1 2 4 5)) The algorithm I used is bubble sort. And I modified it to deal with lists. However, the code doesn't compile. The error is mcar: contract violation expected: mpair? given: 4 Can someone correct my code and explain it. Thank you (define (bubble L) (if (null? (cdr L)) L (if (< (car (car L)) (car (cadr L))) (list (car L)

Sorting list with custom order in Python

有些话、适合烂在心里 提交于 2021-01-27 19:43:08
问题 Hello I currently have two lists, as shown below: list1 = [Alpha, Beta, Charlie, Delta, Echo] list2 = [B, A, E, C, D] I would like to use list2 to sort list1, I have tried using: list1.sort(key=list2.index) However, the letters are unable to be found within the word. Is there a way to sort list1 without each of their full name? 回答1: You must sort according to the first letter of the words: list1 = ['Alpha', 'Beta', 'Charlie', 'Delta', 'Echo'] list2 = ['B', 'A', 'E', 'C', 'D'] out = list

Sorting list with custom order in Python

廉价感情. 提交于 2021-01-27 19:21:14
问题 Hello I currently have two lists, as shown below: list1 = [Alpha, Beta, Charlie, Delta, Echo] list2 = [B, A, E, C, D] I would like to use list2 to sort list1, I have tried using: list1.sort(key=list2.index) However, the letters are unable to be found within the word. Is there a way to sort list1 without each of their full name? 回答1: You must sort according to the first letter of the words: list1 = ['Alpha', 'Beta', 'Charlie', 'Delta', 'Echo'] list2 = ['B', 'A', 'E', 'C', 'D'] out = list

special sorting algorithm and generic signature

南楼画角 提交于 2021-01-27 18:48:09
问题 I have a strong use-case to define my own sorting algorithm, which is faster than the fastest in stl and by exploiting some nice properties of the underlying data I basically can sort in O(n) . So far so good, now the problem is that I would like to offer a generic interface which will fit any type of container e.g. T* or std::vector<T> etc, as long as couple of key concepts apply e.g. there is a valid operator [] available to access the elements of the collection the elements of the

Change sort order of strings includes with a special character (e.g. “_”)

强颜欢笑 提交于 2021-01-27 14:01:49
问题 A PHP script outputs a list of e-mail addresses in descending order like following: _abc_@testmail.com _abc45_@testmail.com _abc2_@testmail.com ypaux2aux@yahoo.com yaremchuk56@testmail.com vasillevn@hotmail.com ugur@hotmail.com twes@gmail.com tukaux@yahoo.com ttsetaux1@yahoo.com tra@testmail.com In Java, I'm creating an ArrayList from these e-mails, then sorting in descending order. The result is different: ypaux2aux@yahoo.com yaremchuk56@testmail.com vasillevn@hotmail.com ugur@hotmail.com

Move null elements for each row in 2d array to the end of that row

落花浮王杯 提交于 2021-01-27 14:01:03
问题 Let's say I have a 2d array which looks like this: [[O, X, null, O, O, null, null], [null, null, O, null, null, O, O]] And I want it to look like this: [[O, X, O, O, null, null, null], [O, O, O, null, null, null, null]] I tried this, but it's not working: String[][] a = new String[row][col]; String[][] b = new String[row][col]; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length; j++) { if (a[i][j] != null) { a[i][j] = b[i][j]; } else { b[i][j] = a[i][j + 1]; } } } 回答1: Some

python: sorting an ordered dictionary

♀尐吖头ヾ 提交于 2021-01-27 13:57:09
问题 I create a dictionary: d[1] = {'a':1, 'b':2} d[2] = {'a':5, 'b':3} d[3] = {'a':3, 'b':2} I then try to sort by a field: d = collections.OrderedDict(sorted(d.items(), key=itemgetter(1))) so that I can output: for key in d: print key, d[key] This sorts on 'a', but I can't figure out how to sort on 'b'. How do I sort on 'b'? EDIT: I'm not sure how this is unclear. I'd like to sort so that the output is ordered by the values in field 'b'. 回答1: Modify your key function so that it explicitly

Scope Order by Count with Conditions Rails

穿精又带淫゛_ 提交于 2021-01-27 12:27:46
问题 I have a model Category that has_many Pendencies . I would like to create a scope that order the categories by the amount of Pendencies that has active = true without excluding active = false . What I have so far is: scope :order_by_pendencies, -> { left_joins(:pendencies).group(:id).order('COUNT(pendencies.id) DESC')} This will order it by number of pendencies, but I want to order by pendencies that has active = true . Another try was: scope :order_by_pendencies, -> { left_joins(:pendencies)