compare

Find oldest/youngest datetime object in a list

好久不见. 提交于 2019-12-17 15:24:44
问题 I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future. from datetime import datetime datetime_list = [ datetime(2009, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2011, 10, 12, 10, 10), #future datetime(2012, 10, 12, 10, 10), #future ] What's the most optimal way to do so? I was thinking of comparing datetime.now() to each one of those. 回答1: Oldest: oldest = min(datetimes)

Stream.max(Integer::max) : Unexpected result [duplicate]

大憨熊 提交于 2019-12-17 13:56:15
问题 This question already has answers here : Java 8 stream's .min() and .max(): why does this compile? (5 answers) Closed 3 years ago . I'm studying for 1z0-809 : Java SE 8 Programmer II using Enthuware's mocktests. Encountering this question. List<Integer> ls = Arrays.asList(3,4,6,9,2,5,7); System.out.println(ls.stream().reduce(Integer.MIN_VALUE, (a, b)->a>b?a:b)); //1 System.out.println(ls.stream().max(Integer::max).get()); //2 System.out.println(ls.stream().max(Integer::compare).get()); //3

How to tell if a date is between two other dates in Python?

泄露秘密 提交于 2019-12-17 10:36:15
问题 I have the following codes: if date in (start, end): print 'in between' else: print 'No!' date, start and end are all variables with the format of 1/1. What should I do to have it print out the right result? i tried date as 10/2, start as 3/14 and end as 11/7 and it's print 'No!', which means it's not running right. I guess have to format them to a date format and then compare them. Thanks for any help! 回答1: As you are still not satisfied, I have another answer for you. Without using datetime

Compare RGB colors in c#

霸气de小男生 提交于 2019-12-17 06:39:11
问题 I'm trying to find a way to compare two colors to find out how much they are alike. I can't seem to find any resources about the subject so I'm hoping to get some pointers here. Idealy, I would like to get a score that tells how much they are alike. For example, 0 to 100, where 100 would be equal and 0 would be totally different. Thanks! Edit: Getting to know a bit more about colors from the answers I understand my question was a bit vague. I will try to explain what I needed this for. I have

Compare JavaScript Array of Objects to Get Min / Max

蹲街弑〆低调 提交于 2019-12-17 05:47:06
问题 I have an array of objects and I want to compare those objects on a specific object property. Here's my array: var myArray = [ {"ID": 1, "Cost": 200}, {"ID": 2, "Cost": 1000}, {"ID": 3, "Cost": 50}, {"ID": 4, "Cost": 500} ] I'd like to zero in on the "cost" specifically and a get a min and maximum value. I realize I can just grab the cost values and push them off into a javascript array and then run the Fast JavaScript Max/Min. However is there an easier way to do this by bypassing the array

Compare JavaScript Array of Objects to Get Min / Max

心已入冬 提交于 2019-12-17 05:47:03
问题 I have an array of objects and I want to compare those objects on a specific object property. Here's my array: var myArray = [ {"ID": 1, "Cost": 200}, {"ID": 2, "Cost": 1000}, {"ID": 3, "Cost": 50}, {"ID": 4, "Cost": 500} ] I'd like to zero in on the "cost" specifically and a get a min and maximum value. I realize I can just grab the cost values and push them off into a javascript array and then run the Fast JavaScript Max/Min. However is there an easier way to do this by bypassing the array

Efficient way to compare version strings in Java [duplicate]

偶尔善良 提交于 2019-12-17 05:40:58
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do you compare two version Strings in Java? I've 2 strings which contains version information as shown below: str1 = "1.2" str2 = "1.1.2" Now, can any one tell me the efficient way to compare these versions inside strings in Java & return 0 , if they're equal, -1, if str1 < str2 & 1 if str1>str2. 回答1: Requires commons-lang3-3.8.1.jar for string operations. /** * Compares two version strings. * * Use this

Efficient way to compare version strings in Java [duplicate]

南楼画角 提交于 2019-12-17 05:40:53
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do you compare two version Strings in Java? I've 2 strings which contains version information as shown below: str1 = "1.2" str2 = "1.1.2" Now, can any one tell me the efficient way to compare these versions inside strings in Java & return 0 , if they're equal, -1, if str1 < str2 & 1 if str1>str2. 回答1: Requires commons-lang3-3.8.1.jar for string operations. /** * Compares two version strings. * * Use this

Image comparison algorithm

只谈情不闲聊 提交于 2019-12-17 05:21:06
问题 I'm trying to compare images to each other to find out whether they are different. First I tried to make a Pearson correleation of the RGB values, which works also quite good unless the pictures are a litte bit shifted. So if a have a 100% identical images but one is a little bit moved, I get a bad correlation value. Any suggestions for a better algorithm? BTW, I'm talking about to compare thousand of imgages... Edit: Here is an example of my pictures (microscopic): im1: im2: im3: im1 and im2

x86 assembler: floating point compare

对着背影说爱祢 提交于 2019-12-17 04:32:44
问题 As part of a compiler project I have to write GNU assembler code for x86 to compare floating point values. I have tried to find resources on how to do this online and from what I understand it works like this: Assuming the two values I want to compare are the only values on the floating point stack, then the fcomi instruction will compare the values and set the CPU-flags so that the je , jne , jl , ... instructions can be used. I'm asking because this only works sometimes. For example: