sorting

parse JSON array in swift , sort it and find overlapping dates

妖精的绣舞 提交于 2020-02-25 05:55:34
问题 How do I parse this? The array is unnamed, the objects are unnamed? I also need to sort it and find overlaps(identify conflicts) between events IF you guys have any advice there too it will be a huge help for me. [{"title": "Evening Picnic", "start": "November 10, 2018 6:00 PM", "end": "November 10, 2018 7:00 PM"}, {"title": "Nap Break", "start": "November 8, 2018 12:56 PM", "end": "November 8, 2018 1:30 PM"}, {"title": "Football Game", "start": "November 3, 2018 6:14 PM", "end": "November 3,

Group by array using multiple values and sum of array based on group values in loop and sorting array

风格不统一 提交于 2020-02-25 04:31:05
问题 I want to group array values and find total (sum of array value-based of the group by value) and then sort array based on total. I want to group by users by fund type ("Private, VC, Others") and the sum of total fund ("last value") I have set up a demo link here. https://3v4l.org/6WNKE <?php $data = [ [ 'Jon', 'NO', "", "Private", 120 ], [ 'Andew', 'NO', "", "VC", 150 ], [ 'Walid', 'YES', "", "Other", 160 ], [ 'Andew', 'YES', "", "VC", 150 ], [ 'Andew', 'YES', "", "VC", 180 ], [ 'Jon', 'NO',

Sorting multidimensional array

半城伤御伤魂 提交于 2020-02-25 00:44:52
问题 I am adding elements to multidimensional array like this foreach($results as $res){ $fwidth=$res[0]; $fpath=$res[1]; $sub = array ( 'img_w' => $fwidth, 'img_path' => $fpath, ); $widths[] = $sub; } And i want to sort $widths array by 'img_w' from bigger to smaller (DESC). Can anyone help me? Thanks in advance. 回答1: Use PHP's USort() function (user sort), which takes two arguments. The first is the array you want to sort. The second is a function that does the actual sorting (you write it

sort HashMap in reverse? [duplicate]

左心房为你撑大大i 提交于 2020-02-24 12:09:07
问题 This question already has answers here : How to use a Java8 lambda to sort a stream in reverse order? (7 answers) Comparator.reversed() does not compile using lambda (2 answers) Closed 2 years ago . So I came across this method which is able to sort HashMaps by value. public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { return map.entrySet() .stream() .sorted(Map.Entry.comparingByValue()) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue,

More efficient ways to find the number of matching values shared by two iterables?

倖福魔咒の 提交于 2020-02-24 09:16:21
问题 EDIT: Looking for the number of matches not the matches themselves. Cannot solve with sets or [x for x in list1 if x in list2] type manner. list1.count(x) if x in list2 works though. Let's say you have two lists, list1 and list2, and want to find the number of times a value from list1 matches a value from list2. I used the following code to perform this task successfully - sum([x==y for x in list1 for y in list2]) The problem is this code cannot handle larger lists efficiently. Is there a

More efficient ways to find the number of matching values shared by two iterables?

断了今生、忘了曾经 提交于 2020-02-24 09:15:11
问题 EDIT: Looking for the number of matches not the matches themselves. Cannot solve with sets or [x for x in list1 if x in list2] type manner. list1.count(x) if x in list2 works though. Let's say you have two lists, list1 and list2, and want to find the number of times a value from list1 matches a value from list2. I used the following code to perform this task successfully - sum([x==y for x in list1 for y in list2]) The problem is this code cannot handle larger lists efficiently. Is there a

TypeError: '<' not supported between instances of 'dict' and 'dict'

六月ゝ 毕业季﹏ 提交于 2020-02-24 07:06:38
问题 I had a perfectly functioning sort by value in python 2.7 but I'm trying to upgrade to python 3.6 and I get that error: TypeError: '<' not supported between instances of 'dict' and 'dict' Here is my code server_list = [] for server in res["aggregations"]["hostname"]["buckets"]: temp_obj = [] temp_obj.append({"name":server.key}) temp_obj.append({"stat": server["last_log"]["hits"]["hits"][0]["_source"][system].stat}) server_list.append(temp_obj) server_list.sort(key=lambda x: x[0], reverse

Reverse specific key when sorting with multiple keys

核能气质少年 提交于 2020-02-23 10:25:09
问题 When sorting with multiple keys, how can I reverse the order of an individual key? For example: vec.sort_by_key(|k| (foo(k).reverse(), bar(k))); 回答1: You can use sort_by paired with Ordering::reverse instead of sort_by_key . use std::cmp::Ordering; #[derive(Debug)] struct Foo(&'static str, u8); impl Foo { fn name(&self) -> &str { self.0 } fn len(&self) -> u8 { self.1 } } fn main() { let mut vec = vec![Foo("alpha", 1), Foo("beta", 2), Foo("beta", 1)]; vec.sort_by(|a, b| { match a.name().cmp(b

Powershell sort PSObject alphabetically

巧了我就是萌 提交于 2020-02-23 06:16:50
问题 Given a custom powershell object (bar) that is created from json (foo.json) How would you sort the object alphabetically by key? foo.json { "bbb": {"zebras": "fast"}, "ccc": {}, "aaa": {"apples": "good"} } Desired output foo.json { "aaa": {"apples": "good"}, "bbb": {"zebras": "fast"}, "ccc": {} } Example $bar = get-content -raw foo.json | ConvertFrom-Json $bar.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False PSCustomObject System.Object I've tried the

Sort map in descending order java8 [duplicate]

安稳与你 提交于 2020-02-22 08:29:17
问题 This question already has answers here : How to sort a LinkedHashMap by value in decreasing order in java stream? (4 answers) Closed 3 years ago . private static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) { Map<K, V> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted( Map.Entry.comparingByValue() ) .forEachOrdered( e -> result.put(e.getKey(), e.getValue()) ); return result; } This is an example from this post. It