|
How in Scala to find unique items in List?
Started by Vladimir Bezugliy on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
If you refer to the Rosetta Code: Create a Sequence of unique elements
val list = List(1,2,3,4,2,3,4,99) val l2 = list.removeDuplicates // l2: scala.List[scala.Int] = List(1,2,3,4,99)
Since List is immutable, you wont modify....
|
|
Hey. I have a very large array and I want to find the Nth largest value. Trivially I can sort the array and then take the Nth element but I'm only interested in one element so there's probably a better way than sorting the entire array...
Started by ooboo on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The entire sequence maintaining a list of the 5 largest values you find (this will be O(n into an empty list when the largeArray item is greater than the last item of your top-N list, then drop the last item....
|
|
I have some List and TileList controls. How can I get a reference to the list item that's currently under the mouse pointer?
Started by toby on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Add an event listener to each item in your list for mouseOver then in your function it will be the event.currentTarget
There's a simple method in the List/TileList for Flex 3 to do this:
<mx:TileList id="tileList" itemRollOver....
|
Ask your Facebook Friends
|
I have a list which contains a collection of objects.
How can I search for an item in this list where object.Property == myValue
Started by JL on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
item = objects.Find(obj => obj.property==myValue);
You have a few options:
Using :
list.Find(i => i.Property == value); // C# 3.0+ list.Find(delegate(Item i) { return i.Property == value = myList.Find(item => item.property....
|
|
I have an unsorted list of strings. I can place these items in an array, List, SortedList, whatever.
I need to find the fastest way of looking up a string in this list. Am I better off dumping the list into an array, sorting it, then implementing binary...
Started by AngryHacker on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
I'mIf your goal is just to make it very fast to find the strings in a collection, put them,TValue>.Contains is also O(1)....
list, to find different items, then sort it keep the sorted list and do a binary search...
|
|
Given the following:
List<List<Option>> optionLists;
what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value...
Started by JC on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Basically you would do this:
Retrieve the first item from each list Compare the items, if equal that's the fastest....
Var x-sort.
Ok, this will find the list of Option objects that have a Value appearing in every list.
|
|
Int findLargest (ListNode *p) // // Preconditions: list head pointer is passed as a parameter. // Postconditions: returns the largest value in the linked list. // { if (p->item != NULL) { int largest = p->item; if (largest > p->next->item...
Started by Brandon on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Empty list."); return n->next == 0 ? n->item : max(n->item, find_largest(n->next – arguably, taking the smallest item of an empty list isn’t a meaningful operation:
// Precondition: list is....
|
|
I have a list of an arbitrary number of lists, for instance:
[[1,2,3], [3,4,5], [5,6,7], [7,8,9]]
Now I would like a list containing all elements that are present in more than one list:
[3,5,7]
How would I do that?
Thanks!
Started by mathias on
, 11 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
Seen = set() repeated = set() for l in list_of_lists: for i in set(l): if i in seen: repeated.add
from collections import defaultdict init_list = [[1,2,3], [3,4,5], [5,6,7], [7,8,9]] #defaultdict, every new key will have a int(0....
|
|
Sometimes users require to change information in SharePoint list item that is not editable for them, for instance, a field that is hidden in edit form (in my case it was the records number).
I decided to create a small Windows GUI application that the...
Started by naivists on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
; } } if (oActualList == null) { //if there is no list where the URL is the same as provided //we can't hope to find the item return null; } //we need to find the ID from the URL //probably could do with regex the SPSite.AllWebs....
|
|
Given a list of assorted length words, what is the best way to find the maximum length of any words?
For example, the following should return 6
findMaxLen("a,set,of,random,words")
Of course, it's fairly trivial to do this...
<cffunction name="findMaxLen...
Started by Peter Boughton on
, 13 posts
by 13 people.
Answer Snippets (Read the full thread at stackoverflow):
A pseudo linked list :P) Give max as 0 in the begining
int find(LinkedList strings, int max) { int i; String s=(String)strings.element(); for(i=0;s.charAt(i)!='\0';i++); if(strings.hasNext()) return find not a list of strings....
|