EzDevInfo.com

comparison interview questions

Top comparison frequently asked interview questions

Jackson Vs. Gson [closed]

After searching through some existing libraries for JSON, I have finally ended up with these two:

  • Jackson
  • Google GSon

I am a bit partial towards GSON, but word on the net is that GSon suffers from a certain celestial performance issue (as of Sept 2009).

I am continuing my comparison; in the meantime, I'm looking for help to make up my mind.


Source: (StackOverflow)

Why C# fails to compare two object types with each other but VB doesn't?

I have two objects in C# and don't know if it's Boolean or any other type. However when I try to compare those C# fails to give the right answer. I have tried the same code with VB.NET and that did it !

Can anyone tell me how to fix this if there is a solution ?

C#:

object a = true;
object b = true;
object c = false;
if (a == b) c = true;
MessageBox.Show(c.ToString()); //Outputs False !!

VB.NET:

Dim a As Object = True
Dim b As Object = True
Dim c As Object = False
If (a = b) Then c = True
MessageBox.Show(c.ToString()) '// Outputs True

Source: (StackOverflow)

Advertisements

How do I do a case insensitive string comparison in Python?

What's the best way to do case insensitive string comparison in Python?

I would like to encapsulate comparison of a regular strings to a repository string using in a very simple and pythonic way. I also would like to have ability to look up values in a dict hashed by strings using regular python strings. Much obliged for advice.


Source: (StackOverflow)

Python - doctest vs. unittest

I'm trying to get started with unit testing in Python and I was wondering if someone could inform me of the advantages and disadvantages of doctest and unittest. What conditions would you use each for?


Source: (StackOverflow)

How can I check if a Perl array contains a particular value?

I am trying to figure out a way of checking for the existence of a value in an array without iterating through the array.

I am reading a file for a parameter. I have a long list of parameters I do not want to deal with. I placed these unwanted parameters in an array @badparams.

I want to read a new parameter and if it does not exist in @badparams, process it. If it does exist in @badparams, go to the next read.


Source: (StackOverflow)

How do I test one variable against multiple values?

I'm trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say:

x = 0
y = 1
z = 3
Mylist = []

if x or y or z == 0 :
    Mylist.append("c")
elif x or y or z == 1 :
    Mylist.append("d")
elif x or y or z == 2 :
    Mylist.append("e")
elif x or y or z == 3 : 
    Mylist.append("f")

which would return a list of

["c", "d", "f"]

Is something like this possible?


Source: (StackOverflow)

Why does comparing strings in Python using either '==' or 'is' sometimes produce a different result?

I've got a Python program where two variables are set to the value 'public'. In a conditional expression I have the comparison var1 is var2 which fails, but if I change it to var1 == var2 it returns True.

Now if I open my Python interpreter and do the same "is" comparison, it succeeds.

>>> s1 = 'public'
>>> s2 = 'public'
>>> s2 is s1
True

What am I missing here?


Source: (StackOverflow)

Image comparison - fast algorithm

I'm looking to create a base table of images and then compare any new images against that to determine if the new image is an exact (or close) duplicate of the base.

For example: if you want to reduce storage of the same image 100's of times, you could store one copy of it and provide reference links to it. When a new image is entered you want to compare to an existing image to make sure it's not a duplicate ... ideas?

One idea of mine was to reduce to a small thumbnail and then randomly pick 100 pixel locations and compare.


Source: (StackOverflow)

Object comparison in JavaScript [duplicate]

Possible Duplicate:
How do you determine equality for two JavaScript objects?

What is the best way to compare objects in JavaScript?

Example:

var user1 = {name : "nerd", org: "dev"};
var user2 = {name : "nerd", org: "dev"};
var eq = user1 == user2;
alert(eq); // gives false

I know that two objects are equal if they refer to the exact same object, but is there a way to check if they have the same attributes' values?

The following way works for me, but is it the only possibility?

var eq = Object.toJSON(user1) == Object.toJSON(user2);
alert(eq); // gives true

Source: (StackOverflow)

What's the difference between equal?, eql?, ===, and ==?

I am trying to understand the difference between these four methods. I know by default that == calls the method equal? which returns true when both operands refer to exactly the same object.

=== by default also calls == which calls equal?... okay, so if all these three methods are not overridden, then I guess ===, == and equal? do exactly the same thing?

Now comes eql?. What does this do (by default)? Does it make a call to the operand's hash/id?

Why does Ruby have so many equality signs? Are they supposed to differ in semantics?


Source: (StackOverflow)

String comparison in Python: is vs. == [duplicate]

I noticed a Python script I was writing was acting squirrelly, and traced it to an infinite loop, where the loop condition was while line is not ''. Running through it in the debugger, it turned out that line was in fact ''. When I changed it to !='' rather than is not '', it worked fine.

Also, is it generally considered better to just use '==' by default, even when comparing int or Boolean values? I've always liked to use 'is' because I find it more aesthetically pleasing and pythonic (which is how I fell into this trap...), but I wonder if it's intended to just be reserved for when you care about finding two objects with the same id.


Source: (StackOverflow)

"is" operator behaves unexpectedly with integers

Why does the following behave unexpectedly in Python?

>>> a = 256
>>> b = 256
>>> a is b
True           # This is an expected result
>>> a = 257
>>> b = 257
>>> a is b
False          # What happened here? Why is this False?
>>> 257 is 257
True           # Yet the literal numbers compare properly

I am using Python 2.5.2. Trying some different versions of Python, it appears that Python 2.3.3 shows the above behaviour between 99 and 100.

Based on the above, I can hypothesize that Python is internally implemented such that "small" integers are stored in a different way than larger integers and the is operator can tell the difference. Why the leaky abstraction? What is a better way of comparing two arbitrary objects to see whether they are the same when I don't know in advance whether they are numbers or not?


Source: (StackOverflow)

Optimum way to compare strings in Javascript? [duplicate]

This question already has an answer here:

I am trying to optimize a function which does binary search of strings in Javascript.

Binary search requires you to know whether the key is == the pivot or < the pivot.

But this requires two string comparisons in Javascript, unlike in C like languages which have the strcmp() function that returns three values (-1, 0, +1) for (less than, equal, greater than).

Is there such a native function in Javascript, that can return a ternary value so that just one comparison is required in each iteration of the binary search?


Source: (StackOverflow)

Why are the built in functions in PHP named so randomly? [closed]

It seems that there is no real pattern to the way functions are named, str_replace, strrpos, strip_tags, stripslashes are just some.

Why is this the case?

EDIT - this wasn't meant as a "troll" type post - just something that I think everytime I use the language!


Source: (StackOverflow)