|
There are many ways to do this but I feel like I've missed a function or something.
Obviously List == List will use Object.Equals() and return false.
If every element of the list is equal and present in the same location in the opposite list then I would...
Started by Spence on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
T> x, List<T> y) { // same list or both are null if (x == y) { return true; } // one is null.
|
|
In my list:
animals = [ ['dog', ['bite'] ], ['cat', ['bite', 'scratch'] ], ['bird', ['peck', 'bite'] ], ] add('bird', 'peck') add('bird', 'screech') add('turtle', 'hide')
The add function should check that the animal and action haven't been added before...
Started by Tom on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
It is possible to construct a generic function that finds the animal in the list using a.index or testing.
|
|
Okay I'm trying to go for a more pythonic method of doing things.
How can i do the following:
required_values = ['A','B','C'] some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4} for required_value in required_values: if not required_value in some_map: print...
Answer Snippets (Read the full thread at stackoverflow):
Map.keys()))
try a list comprehension:
return not bool([x for x in required_values if x not in some not in some_map.keys()] (i think the more pythonic way)
The inside [] statement builds a list of all required values not in your map keys....
|
Ask your Facebook Friends
|
I've sometimes had a problem with my field-, table-, view- oder stored procedure names. Example:
SELECT from, to, rate FROM Table1
The Problem is that from is a reserved word in SQL-92. You could put the fieldname in double quotes to fix this, but what...
Started by shmia on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
You can use that as a sanity-check on application.
Of programmatically listing all reserved words.
|
|
I find myself writing code that looks like this a lot:
set<int> affected_items; while (string code = GetKeyCodeFromSomewhere()) { if (code == "some constant" || code == "some other constant") { affected_items.insert(some_constant_id); } else if ...
Started by MattSmith on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Into a sort of "to do list." For example:
while (string code = GetKeyCodeFromSomewhere()) { todo.
|
|
Hello,
This is an interview question for which I don't have an answer. Given Two lists, You cannot change list and you dont know the length. Give best possible algorithm to:
Check if two lists are merging at any point? If merging, at what point they are...
Started by claws on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Second is better at worst case create a hash table ... .
First approach is faster when your lists merge early, as you don't need to store all nodes from first list.
Nodes in Set and then only check second list against that Set.
|
|
I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How?
I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a ...
Started by merci on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Assuming list2) (list (difference lis1 lis2) ....
Sure it is possible.
Take a piece at a time.
Here are a couple hints:
what's the result of combining a list and an empty list? You don't have to do it all at once.
Sure it's possible.
|
|
Hi,
I have a list of two-item lists and need to search for things in it.
If the list is:
list =[ ['a','b'], ['a','c'], ['b','d'] ]
I can search for a pair easily by doing
['a','b'] in list
Now, is there a way to see if I have a pair in which a string ...
Started by joaoc on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The asterisk takes the contents of the_list is what zip wants.....
Gt; "b" in zip(*the_list)[1] True
zip() takes a bunch of lists and groups elements together by index, effectively transposing the list-of-lists matrix.
|
|
Below is some linqpad test code. When this runs it errors because the second instance of "item" has a null list of subitems as opposed to an empty list.
I want to treat both situations (null or empty list) in exactly the same way but I wondered if there...
Started by Chris Simpson on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You could make the item constructor so that it defaults subitem to an empty list.
Subitems to be null.
|
|
I have to implement an algorithm to decompose 3D volumes in voxels. The algorithm starts by identifying which vertexes is on each side of the cut plan and in a second step which edge traverse the cutting plan.
This process could be optimized by using ...
Started by chmike on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
If you have a sorted list, adding to it takes....
The question list, adding to it takes no time, and accessing particular items takes extra time.
The straightforward implementation first, if for no other reason that to check against....
|