list

How do I get a particular derived object in a List<T>?

Let's say I have a generic list of Fruit (List<Fruit> fruits = new List<Fruit>()). I then add a couple of objects (all derived from Fruit) - Banana, Apple, Orange but with different properties on the derived objects (such as Banana.IsYellow). List<Fruit> fruits = new List<Fruit>(); Banana banana1 = new Banana(); Banana banana2 = new Ban...

.NET / C# - Convert List to a SortedList

What is the best way to convert a List to SortedList? Any good way to do it without cycling through it? Any clever way to do it with an OrderBy()? WRAP UP Please read all answers and comments. ...

Initialise a list to a specific length in Python

How do I initialise a list with 10 times a default value in Python? I'm searching for a good-looking way to initialize a empty list with a specific range. So make a list that contains 10 zeros or something to be sure that my list has a specific length. ...

Returning STL lists as argument

I have a function that reads lines from a log file, converts these lines to a certain class and returns a STL list of instances of this class. My question is: how should I declare this function so that the whole list is NOT copied when attributing it to the caller? Without loss of generality, assume: list<Request> requests = log_manipu...

comparing lists and finding unique entries

Hello, I have two lists of names, A and B. I need to produce three lists: 1) names only on A 2) names only on B 3) names on both A and B I also have a list with all the names on A and B, C. Can anyone think of Unix tools or quick scripts to do this? ...

How do I find the index of an undefined string in a List<T>

It's my understanding that if I want to get the ID of an item in a list, I can do this: private static void a() { List<string> list = new List<string> {"Box", "Gate", "Car"}; Predicate<string> predicate = new Predicate<string>(getBoxId); int boxId = list.FindIndex(predicate); } private static bool getBoxId(string item) { ...

jQuery unable to remove list elements

I have a tree with ul and has the following structure: <div id="Tree"> <ul> <li> <a class="collapseLink" href="#"> <span class="hide">Expand Root Node</span> </a> <a class="selectLink" href="#"> Root Node </a> <ul> <li id="item_1">Sub Node 1</li> <li id="item_2">Sub Nod...

Efficient Tuple List Comparisons

I am kind of hitting a wall on this problem and I was wondering if some fresh brains could help me out. I have a large list of four element tuples in the format: (ID number, Type, Start Index, End Index) Previously in the code, I have searched through thousands of blocks of text for two specific types of substrings. These tuples stor...

WSS 3.0 - Can not display created custom template lists with web services

I have created a custom list from another list in sharepoint, it is saved into the "List Template Gallery" I need to get this new list template by using web services, but the .GetListTemplates method of lists does not retrieve the custom templates. How can I get the custom templates?, so then I can use it to create a list. ...

How do I make a Lazy List in an Eager Language?

I wanted to make a lazy list in Scheme. This is what I have so far. ;; Constructor for Pairs (define (cons-stream a b) (cons a (λ() b))) ;; Selectors (define (car-stream a-stream) (car a-stream)) (define (cdr-stream a-stream) ((cdr a-stream))) ;; Lazy List using the pairs (define (lazy-list from) (cons-stream from (lazy-list ...

ExceptionList Class - VB

Hi, I need to return an exception that contains a list of exceptions. This is easy enough to do, but I'd like to know if there is a built-in Exception Class that does this as I'd hate to "roll my own" instead of following built-in, documented classes. Thanks, Larry ...

Problem adding validation list in excel sheet using VBA

I have an excel sheet that is loaded with a dynamic result set of data. I need to add a YES/NO dropdown at the end of each row once all the data is loaded. I have to do this dynamically as I do not know the size of the result set beforehand. The following code throws an 'Applicaton-defined or object-defined error': Dim firstRow As Integ...

haskell polymorphism and lists

Suppose I have the following: class Shape a where draw a :: a -> IO () data Rectangle = Rectangle Int Int instance Shape Rectangle where draw (Rectangle length width) = ... data Circle = Circle Int Int instance Shape Circle where draw (Circle center radius) = ... Is there any way for me to define a list of shapes, trav...

Compare two lists or arrays of arbitrary length in C#; order is important

Say I have two lists or arrays of strings. For example: list 1: "a", "c", "b", "d", "f", "e" list 2: "a", "d", "e", "f", "h" List 1 and list 2 are of arbitrary lengths. List 1 may contain elements not in list 2, and visa versa. I'd like to know when items in list 1 are found in list 2, and more specifically I want to know when an i...

how can i list every path in a directed graph? (C#)

please just point me in the right direction or tell me what to look up to solve this: I have a "tree" object that holds "node" objects. (actually it's called a directed graph). Each node holds the fields string "name" and "list" that contains the next nodes. How can I create lists of all possible node names from the head node to the fo...

Handle either a list or single integer as an argument

A function should select rows in a table based on the row name (column 2 in this case). It should be able to take either a single name or a list of names as arguments and handle them correctly. This is what I have now, but ideally there wouldn't be this duplicated code and something like exceptions would be used intelligently to choose ...

php list into a table

I asked a question yesterday and the answer I got has answered the first part of my problem - I now have a query that generates a list similar to this: fname, sname, uname, assignment, task, grade joe, blogs, joe.blogs, 1, 1, 52 joe, blogs, joe.blogs, 1, 2, 58 jim, blogs, jim.blogs, 1, 1, 95 jim, blogs, jim.blogs, 1, 2, 86 amy, blogs, a...

Nhibernate - Initialize lists - Best Practice?

Hi, I was just wondering about some CodeWarning (ConstructorsShouldNotCallBaseClassVirtualMethods), and if there is a better way to do it. I have a simple log collector class, and I am using NHibernate to retrieve some of the objects. Some times I create objects by myself (of course) and add them to NHibernate for persistance. What is t...

WPF Create generic "Selector Tool" for multiple classes

Hi, the problem is pretty easy if you reduce it to one class. Given the following image, I want to create a simple two sided control, which puts items from one list into the other depending on a boolean value. EDIT: You can of course click on items in both lists, and the item switches to the other list. Also, a callback is called, in ca...

In a SharePoint web part, how do I set a web part's list during run-time?

I have a Contact List web part I developed that is dependent on a custom list I created, also called Contact List. But instead of the web part ALWAYS requiring a list called Contact List whenever the web part is added to a page, I want it so I can add the web part to a page THEN set which list I want it to use. I guess I am asking how do...