Search Results

Search found 2896 results on 116 pages for 'comparison operators'.

Page 21/116 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • Common elements comparison between 2 lists.

    - by Daniel
    def common_elements(list1, list2): """ Return a list containing the elements which are in both list1 and list2 >>> common_elements([1,2,3,4,5,6], [3,5,7,9]) [3, 5] >>> common_elements(['this','this','n','that'],['this','not','that','that']) ['this', 'that'] """ for element in list1: if element in list2: return list(element) Got that so far, but can't seem to get it to work! Thanks

    Read the article

  • classic asp comparison of comma seperated lists

    - by Reiwoldt
    Hello, I have two comma seperated lists:- 36,189,47,183,65,50 65, 50, 189, 47 the question is how to compare the two in classic ASP in order to identify and return any values that exist in list 1 but that don't exist in list 2 bearing in mind that associative arrays aren't available. e.g. in the above example I would need the return value to be 36,183 Thanks

    Read the article

  • MySQL Join/Comparison on a DATETIME column (<5.6.4 and > 5.6.4)

    - by Simon
    Suppose i have two tables like so: Events ID (PK int autoInc), Time (datetime), Caption (varchar) Position ID (PK int autoinc), Time (datetime), Easting (float), Northing (float) Is it safe to, for example, list all the events and their position if I am using the Time field as my joining criteria? I.e.: SELECT E.*,P.* FROM Events E JOIN Position P ON E.Time = P.Time OR, even just simply comparing a datetime value (taking into consideration that the parameterized value may contain the fractional seconds part - which MySQL has always accepted) e.g. SELECT E.* FROM Events E WHERE E.Time = @Time I understand MySQL (before version 5.6.4) only stores datetime fields WITHOUT milliseconds. So I would assume this query would function OK. However as of version 5.6.4, I have read MySQL can now store milliseconds with the datetime field. Assuming datetime values are inserted using functions such as NOW(), the milliseconds are truncated (<5.6.4) which I would assume allow the above query to work. However, with version 5.6.4 and later, this could potentially NOT work. I am, and only ever will be interested in second accuracy. If anyone could answer the following questions would be greatly appreciated: In General, how does MySQL compare datetime fields against one another (consider the above query). Is the above query fine, and does it make use of indexes on the time fields? (MySQL < 5.6.4) Is there any way to exclude milliseconds? I.e. when inserting and in conditional joins/selects etc? (MySQL 5.6.4) Will the join query above work? (MySQL 5.6.4) EDIT I know i can cast the datetimes, thanks for those that answered, but i'm trying to tackle the root of the problem here (the fact that the storage type/definition has been changed) and i DO NOT want to use functions in my queries. This negates all my work of optimizing queries applying indexes etc, not to mention having to rewrite all my queries. EDIT2 Can anyone out there suggest a reason NOT to join on a DATETIME field using second accuracy?

    Read the article

  • C# Type comparison

    - by Sean.C
    This has me pooped, is there any reason the following: public abstract class aExtension { public abstract bool LoadExtension(Constants c); // method required in inherit public abstract string AppliesToModule // property required in inherit { get; } public abstract string ExtensionName // property required in inherit { get; } public abstract string ExtensionDescription // property required in inherit { get; } } public class UK : aExtension { public override bool LoadExtension(Constants c) { return true; } public override string AppliesToModule { get { return "string"; } } public override string ExtensionName { get { return "string"; } } public override string ExtensionDescription { get { return "string"; } } } would return false for the following expressions: bool a = t.IsAssignableFrom(aExtension)); bool b = t.BaseType.IsAssignableFrom(aExtension)); bool c = typeof(aExtension).IsAssignableFrom(t); bool d = typeof(aExtension).IsAssignableFrom(t.BaseType); bool e = typeof(aExtension).IsSubclassOf(t); bool f = typeof(aExtension).IsSubclassOf(t.BaseType); bool g = t.IsSubclassOf(typeof(aExtension)); bool h = t.BaseType.IsSubclassOf(typeof(LBT.AdMeter.aExtension)); bool i = t.BaseType.Equals(typeof(aExtension)); bool j = typeof(aExtension).Equals(t.BaseType); T is the reflected Type from the calss UK. Stange thing is i do the exact same thing just on an external assembly in the same application and it works as expected...

    Read the article

  • comparison between point and integer

    - by LawVS
    Right, basically I want to add two numbers together. It's for a working hours calculator and I've included parameters for a night shift scenario as an if statement. However, it now mucks up the day shift pattern. So I want to sort out that if the start time is below 12, then it'll revert to the original equation shown in the code instead of the if statement. -(IBAction)done:(id)sender { int result = [finishHours.text intValue] - [startHours.text intValue]; totalHours.text = [NSString stringWithFormat:@"%d", result]; if (result < 0) { totalHours.text = [NSString stringWithFormat:@"%d", result * -1]; } if (result < 12) { totalHours.text = [NSString stringWithFormat:@"%d", result + 24]; } if (startHours < 12) { totalHours.text = [NSString stringWithFormat:@"%d", result - 24]; }

    Read the article

  • Comparison of IPEndPoint objects not working

    - by Martin Mizzell
    I have an IPEndPoint a and b, whose IPAddress and Port are exactly the same, but the == operator is on the IPEndPoint not returning true. To make things even stranger, I tried to circumvent the problem by simply comparing the IPAddress and Port individually and it is STILL not returning true. Has anyone encountered this before? If so, I am all ears to performant solutions. We have collections of as many as 10k IPEndPoints and are querying into them via LINQ (PLINQ pretty soon).

    Read the article

  • Sort MySQL result set using comparison between 2 columns of same value type

    - by Kyobul
    Hello, I have a table containing last_updated_1 and last_updated_2 columns, used respectively for text and images update time on a post. I wish I could get a result set of 10 rows based on all time last updated records contained in the 2 columns, ex. row 1 = last_updated_1 record, row 2 = last_updated_2 record, row 3 = last_updated_1 record, etc. How could I compare inside a MySQL query the both columns values, to get unique & mixed result set ? Thank you in advance for your help

    Read the article

  • Boolean comparison of array of strings in Ruby

    - by Kyle Kaitan
    I've got an array in Ruby that essentially represents a square boolean matrix. Dots represent zeroes, while any other character represents ones. Example: irb(main):044:0> g => [".b", "m."] # This grid has two '1' values and two '0' values. I'd like to perform a specified logical operation (say, OR) on this array with another similar array to get a third result. For example, if h is ["q.", "r."], then something akin to g.perform_or(h) should yield a new array ["qb", "r."]. (The choice of r to represent the result of 'm' || 'r' is arbitrary and not relevant; any other non-'.' character can be there.) How might I do this? Edit: I made an error in my example. Apologies!

    Read the article

  • Scientific Data processing (Graph comparison and interpretation)

    - by pinkynobrain
    Hi stackoverflow friends, I'm trying to write a program to automate one of my more boring and repetitive work tasks. I have some programming experience but none with processing or interpreting large volumes of data so I am seeking your advice (both suggestions of techniques to try and also things to read to learn more about doing this stuff). I have a piece of equipment that monitors an experiment by taking repeated samples and displays the readings on its screen as a graph. The input of experiment can be altered and one of these changes should produce a change in a section of the graph which I currently identify by eye and is what I'm looking for in the experiment. I want to automate it so that a computer looks at a set of results and spots the experiment input that causes the change. I can already extract the results from the machine. Currently they results for a run are in the form of an integer array with the index being the sample number and the corresponding value being the measurement. The overall shape of the graph will be similar for each experiment run. The change I'm looking for will be roughly the same and will occur in approximately the same place every time for the correct experiment input. Unfortunately there are a few gotchas that make this problem more difficult. There is some noise in the measuring process which mean there is some random variation in the measured values between different runs. Although the overall shape of the graph remains the same. The time the experiment takes varies slightly each run causing two effects. First, the a whole graph may be shifted slightly on the x axis relative to another run's graph. Second, individual features may appear slightly wider or narrower in different runs. In both these cases the variation isn't particularly large and you can assume that the only non random variation is caused by the correct input being found. Thank you for your time, Pinky

    Read the article

  • binary number comparison

    - by EquinoX
    If I have a 32 bit two's complement number and I want to know what is the easiest way to know of two numbers are equal... what would be the fastest bitwise operator to know this? I know xor'ing both numbers and check if the results are zero works well... any other one's? how about if a number is greater than 0?? I can check the 31'st bit to see if it's greater or equal to 0..but how about bgtz?

    Read the article

  • date comparison inside a list returned

    - by rob
    I have a ArrayList returned from a service which contains date-timestamp as String values (with values: 2010-05-06T23:38:18,2010-05-06T23:32:52,2010-04-28T18:23:06,2010-04-27T20:34:02,2010-04-27T20:37:02) to be more specific, This is part of a parent ArrayList ObjectHistory. This list contains the datestamp and serial number. I need to pick the correct serial number. Objecthistory is the List object and I need to get the latest timestamp within this ObjectHistory. I need to pick the latest timestamp from this Arraylist in Java 6. How should I be doing this? Should I do convert these values into calendar-time? I am in panic mode as this has to be done directly in production.

    Read the article

  • String comparison in Java

    - by Kliver Max
    I want to compare two strings using Java. First sting name i get from .mif file using GDAL in cp1251 encoding. Second kadname i get from jsp. To compare i do this: if (attrValue instanceof String) { String string3 = new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251"); dbFeature.setAttribute(name, string3); System.out.println("Name=" + name); System.out.println("kadname=" + kadname); if (name.equalsIgnoreCase(kadname)) { kadnum = string3; System.out.println("string3" + string3); } } And in console i get this: Name = kadnumm kadname = kadnumm Whats wrong with this?

    Read the article

  • J2EE v6 and .NET 4.0 comparison

    - by sme89288
    We are running our applications on .NET 3.5 and are planning on either updating to .NET 4.0 or switching entirely to the Java platform, J2EE v6, as we've heard from some clients that "it's better." Can anyone either explain some of the large differences between the two platforms and maybe what kind of costs would be associated with switching to Java rather than just updating, or point me to some articles or papers that make such comparisons? Thanks!

    Read the article

  • An operator == whose parameters are non-const references

    - by Eduardo León
    I this post, I've seen this: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString& lhs, /*const*/ MonitorObjectString& rhs) { return lhs.fVal==rhs.fVal; } } Before we can continue, THIS IS VERY IMPORTANT: I am not questioning anyone's ability to code. I am just wondering why someone would need non-const references in a comparison. The poster of that question did not write that code. This was just in case. This is important too: I added both /*const*/s and reformatted the code. Now, we get back to the topic: I can't think of a sane use of the equality operator that lets you modify its by-ref arguments. Do you?

    Read the article

  • Advantages/Disadvantages of different implementations for Comparing Objects using .NET

    - by Kevin Crowell
    This questions involves 2 different implementations of essentially the same code. First, using delegate to create a Comparison method that can be used as a parameter when sorting a collection of objects: class Foo { public static Comparison<Foo> BarComparison = delegate(Foo foo1, Foo foo2) { return foo1.Bar.CompareTo(foo2.Bar); }; } I use the above when I want to have a way of sorting a collection of Foo objects in a different way than my CompareTo function offers. For example: List<Foo> fooList = new List<Foo>(); fooList.Sort(BarComparison); Second, using IComparer: public class BarComparer : IComparer<Foo> { public int Compare(Foo foo1, Foo foo2) { return foo1.Bar.CompareTo(foo2.Bar); } } I use the above when I want to do a binary search for a Foo object in a collection of Foo objects. For example: BarComparer comparer = new BarComparer(); List<Foo> fooList = new List<Foo>(); Foo foo = new Foo(); int index = fooList.BinarySearch(foo, comparer); My questions are: What are the advantages and disadvantages of each of these implementations? What are some more ways to take advantage of each of these implementations? Is there a way to combine these implementations in such a way that I do not need to duplicate the code? Can I achieve both a binary search and an alternative collection sort using only 1 of these implementations?

    Read the article

  • Non-latin-characters ordering in database with "order by"

    - by nybon
    I just found some strange behavior of database's "order by" clause. In string comparison, I expected some characters such as '[' and '_' are greater than latin characters such as 'i' considering their orders in the ASCII table. However, the sorting results from database's "order by" clause is different with my expectation. Here's my test: SQLite version 3.6.23 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table products(name varchar(10)); sqlite> insert into products values('ipod'); sqlite> insert into products values('iphone'); sqlite> insert into products values('[apple]'); sqlite> insert into products values('_ipad'); sqlite> select * from products order by name asc; [apple] _ipad iphone ipod This behavior is different from Java's string comparison (which cost me some time to find this issue). I can verify this in both SQLite 3.6.23 and Microsoft SQL Server 2005. I did some web search but cannot find any related documentation. Could someone shed me some light on it? Is it a SQL standard? Where can I find some information about this? Thanks in advance.

    Read the article

  • heterogeneous comparisons in python3

    - by Matt Anderson
    I'm 99+% still using python 2.x, but I'm trying to think ahead to the day when I switch. So, I know that using comparison operators (less/greater than, or equal to) on heterogeneous types that don't have a natural ordering is no longer supported in python3.x -- instead of some consistent (but arbitrary) result we raise TypeError instead. I see the logic in that, and even mostly think its a good thing. Consistency and refusing to guess is a virtue. But what if you essentially want the python2.x behavior? What's the best way to go about getting it? For fun (more or less) I was recently implementing a Skip List, a data structure that keeps its elements sorted. I wanted to use heterogeneous types as keys in the data structure, and I've got to compare keys to one another as I walk the data structure. The python2.x way of comparing makes this really convenient -- you get an understandable ordering amongst elements that have a natural ordering, and some ordering amongst those that don't. Consistently using a sort/comparison key like (type(obj).__name__, obj) has the disadvantage of not interleaving the objects that do have a natural ordering; you get all your floats clustered together before your ints, and your str-derived class separates from your strs. I came up with the following: import operator def hetero_sort_key(obj): cls = type(obj) return (cls.__name__+'_'+cls.__module__, obj) def make_hetero_comparitor(fn): def comparator(a, b): try: return fn(a, b) except TypeError: return fn(hetero_sort_key(a), hetero_sort_key(b)) return comparator hetero_lt = make_hetero_comparitor(operator.lt) hetero_gt = make_hetero_comparitor(operator.gt) hetero_le = make_hetero_comparitor(operator.le) hetero_ge = make_hetero_comparitor(operator.gt) Is there a better way? I suspect one could construct a corner case that this would screw up -- a situation where you can compare type A to B and type A to C, but where B and C raise TypeError when compared, and you can end up with something illogical like a > b, a < c, and yet b > c (because of how their class names sorted). I don't know how likely it is that you'd run into this in practice.

    Read the article

  • C# - Advantages/Disadvantages of different implementations for Comparing Objects

    - by Kevin Crowell
    This questions involves 2 different implementations of essentially the same code. First, using delegate to create a Comparison method that can be used as a parameter when sorting a collection of objects: class Foo { public static Comparison<Foo> BarComparison = delegate(Foo foo1, Foo foo2) { return foo1.Bar.CompareTo(foo2.Bar); }; } I use the above when I want to have a way of sorting a collection of Foo objects in a different way than my CompareTo function offers. For example: List<Foo> fooList = new List<Foo>(); fooList.Sort(BarComparison); Second, using IComparer: public class BarComparer : IComparer<Foo> { public int Compare(Foo foo1, Foo foo2) { return foo1.Bar.CompareTo(foo2.Bar); } } I use the above when I want to do a binary search for a Foo object in a collection of Foo objects. For example: BarComparer comparer = new BarComparer(); List<Foo> fooList = new List<Foo>(); Foo foo = new Foo(); int index = fooList.BinarySearch(foo, comparer); My questions are: What are the advantages and disadvantages of each of these implementations? What are some more ways to take advantage of each of these implementations? Is there a way to combine these implementations in such a way that I do not need to duplicate the code? Can I achieve both a binary search and an alternative collection sort using only 1 of these methods?

    Read the article

  • event.clientX is readonly?

    - by Duracell
    Working in IE 8, mostly, but trying to write a portable solution for modern browsers. Using telerik controls. I'm catching the 'Showing' client-side event of the RadContextMenu and trying to adjust it's coordinates. The clientX, clientY and x,y members of the DOM event cannot be assigned a new value. Visual Studio breaks with a "htmlfile: Member not found" error. My goal is to get a RadContextMenu to show inside a RadEditor when the user clicks in it (under certain conditions, this is a requirement from management). So I capture the onclick event for the RadEditor's content area (radEditor.get_document().body;). I then call show(evt) on the context menu, where 'evt' is the event object corresponding to the click event. Because the RadEditor's content is in an IFRAME, you have to adjust the position of the click event before the context menu displays. This is done in the "Showing" event. However, I cannot assign a value to the members .clientX and friends. It's as if javascript has temporarily forgotten about integer + and += operators. Is it possible that these members have become readonly/const at some point? var evt = args.get_domEvent(); while (node) { evt.clientX += node.offsetLeft; //'Member not found' here. evt.clientY += node.offsetTop; node = node.offsetParent; } evt.clientY += sender.get_element().clientHeight;

    Read the article

  • How to pass multiple different records (not class due to delphi limitations) to a function?

    - by mingo
    Hi to all. I have a number of records I cannot convert to classes due to Delphi limitation (all of them uses class operators to implement comparisons). But I have to pass to store them in a class not knowing which record type I'm using. Something like this: type R1 = record begin x :Mytype; class operator Equal(a,b:R1) end; type R2 = record begin y :Mytype; class operator Equal(a,b:R2) end; type Rn = record begin z :Mytype; class operator Equal(a,b:Rn) end; type TC = class begin x : TObject; y : Mytype; function payload (n:TObject) end; function TC.payload(n:TObject) begin x := n; end; program: c : TC; x : R1; y : R2; ... c := TC.Create(): n:=TOBject(x); c.payload(n); Now, Delphi do not accept typecast from record to TObject, and I cannot make them classes due to Delphi limitation. Anyone knows a way to pass different records to a function and recognize their type when needed, as we do with class: if x is TMyClass then TMyClass(x) ... ???

    Read the article

  • Bitwise OR of constants

    - by ryyst
    While reading some documentation here, I came across this: unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *comps = [gregorian components:unitFlags fromDate:date]; I have no idea how this works. I read up on the bitwise operators in C, but I do not understand how you can fit three (or more!) constants inside one int and later being able to somehow extract them back from the int? Digging further down the documentation, I also found this, which is probably related: typedef enum { kCFCalendarUnitEra = (1 << 1), kCFCalendarUnitYear = (1 << 2), kCFCalendarUnitMonth = (1 << 3), kCFCalendarUnitDay = (1 << 4), kCFCalendarUnitHour = (1 << 5), kCFCalendarUnitMinute = (1 << 6), kCFCalendarUnitSecond = (1 << 7), kCFCalendarUnitWeek = (1 << 8), kCFCalendarUnitWeekday = (1 << 9), kCFCalendarUnitWeekdayOrdinal = (1 << 10), } CFCalendarUnit; How do the (1 << 3) statements / variables work? I'm sorry if this is trivial, but could someone please enlighten me by either explaining or maybe posting a link to a good explanation? Thanks! -- ry

    Read the article

  • What are the default return values for operator< and operator[] in C++ (Visual Studio 6)?

    - by DustOff
    I've inherited a large Visual Studio 6 C++ project that needs to be translated for VS2005. Some of the classes defined operator< and operator[], but don't specify return types in the declarations. VS6 allows this, but not VS2005. I am aware that the C standard specifies that the default return type for normal functions is int, and I assumed VS6 might have been following that, but would this apply to C++ operators as well? Or could VS6 figure out the return type on its own? For example, the code defines a custom string class like this: class String { char arr[16]; public: operator<(const String& other) { return something1 < something2; } operator[](int index) { return arr[index]; } }; Would VS6 have simply put the return types for both as int, or would it have been smart enough to figure out that operator[] should return a char and operator< should return a bool (and not convert both results to int all the time)? Of course I have to add return types to make this code VS2005 C++ compliant, but I want to make sure to specify the same type as before, as to not immediately change program behavior (we're going for compatibility at the moment; we'll standardize things later).

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >