Compare two List objects for equality, ignoring order [duplicate]

This question already has answers here: Comparing two collections for equality irrespective of the order of items in them (20 answers) Closed 4 years ago. Yet another list-comparing question. List<MyType> list1; List<MyType> list2; I need to check that they both have the same elements, regardless of their position within the list. Each MyType object may … Read more

Switch statement for greater-than/less-than

so I want to use a switch statement like this: switch (scrollLeft) { case (<1000): //do stuff break; case (>1000 && <2000): //do stuff break; } Now I know that either of those statements (<1000) or (>1000 && <2000) won’t work (for different reasons, obviously). What I’m asking is the most efficient way to do … Read more

Comparing two dictionaries and checking how many (key, value) pairs are equal

I have two dictionaries, but for simplification, I will take these two: >>> x = dict(a=1, b=2) >>> y = dict(a=2, b=2) Now, I want to compare whether each key, value pair in x has the same corresponding value in y. So I wrote this: >>> for x_values, y_values in zip(x.iteritems(), y.iteritems()): if x_values == … Read more

Check if two unordered lists are equal [duplicate]

This question already has answers here: How to efficiently compare two unordered lists (not sets) in Python? (10 answers) Closed 5 years ago. I’m looking for an easy (and quick) way to determine if two unordered lists contain the same elements: For example: [‘one’, ‘two’, ‘three’] == [‘one’, ‘two’, ‘three’] : true [‘one’, ‘two’, ‘three’] … Read more

What is the rationale for all comparisons returning false for IEEE754 NaN values?

Why do comparisons of NaN values behave differently from all other values? That is, all comparisons with the operators ==, <=, >=, <, > where one or both values is NaN returns false, contrary to the behaviour of all other values. I suppose this simplifies numerical computations in some way, but I couldn’t find an … Read more