list

How do I get a directory listing in Perl?

I would like to execute ls in a Perl program as part of CGI script. For this I used exec(ls), but this does not return from the exec call. Is there a better way to get a listing of a directory in Perl? ...

How do I reverse a list using recursion in Python?

I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that? ...

What are some of the common programming tasks you work with in Real world?

I am working on making a list of all the common programming tasks that any regular developer works with in real world application development. Code that you work with in most regular LOB applications repeatedly. Even if it's not so common, and you think it is fairly worthwhile to add it to the list, please do so. Let me start with: Re...

How do I clone a generic list in C#?

I have a generic list of objects in C#, and wish to clone the list. The items within the list are cloneable, but there doesn't seem to be an option to do list.Clone() Is there an easy way around this? ...

How do I keep Numbered Lists indented in html/css?

How do you keep numbered lists indented using HTML/CSS? I have a page where the digits are not indented and it does not look good. Here is a sample page: http://php.wmsgroup.com/eofd6.org/volunteer.html CSS is at: http://php.wmsgroup.com/eofd6.org/in.css Thanks! ...

Cleanest way to find objects matching certain criteria in a java.util.List?

I could write myself a helper class that does this when given a functor, but I was wondering if there's a better approach, or if there's something already in the standard library (seems like there should be). Answers I've found on StackOverflow are all for C# which doesn't help me. Thanks ...

Passing a list while retaining the original

So I'm teaching myself Python, and I'm having an issue with lists. I want to pass my function a list and pop items off it while retaining the original list. How do I make python "instance" the passed list rather that passing a pointer to the original one? Example: def burninate(b): c = [] for i in range(3): c.append(b.pop(...

Is list::size() really O(n)?

Recently, I noticed some people mentioning that std::list::size() has a linear complexity. According to some sources, this is in fact implementation dependent as the standard doesn't say what the complexity has to be. The comment in this blog entry says: Actually, it depends on which STL you are using. Microsoft Visual Studio V6 ...

Given a list of variable names in Python, how do I a create a dictionary with the variable names as keys (to the variables' values)?

I have a list of variable names, like this: ['foo', 'bar', 'baz'] (I originally asked how I convert a list of variables. See Greg Hewgill's answer below.) How do I convert this to a dictionary where the keys are the variable names (as strings) and the values are the values of the variables? {'foo': foo, 'bar': bar, 'baz': baz} No...

Unexpected feature in a Python list of lists

I needed to create a list of lists in Python, so I typed the following: myList = [[1] * 4] * 3 The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] Then I changed one of the innermost values: myList[0][0] = 5 Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]] which is not what...

How do I form a good predicate delegate to Find() something in my List<T>?

After looking on MSDN, it's still unclear to me how I should form a proper predicate to use the Find() method in List using a member variable of T (where T is a class) For example: public class Car { public string Make; public string Model; public int Year; } { // somewhere in my code List<Car> carList = new List<Car>();...

Looping through 2 Lists at once

I have two lists that are of the same length, is it possible to loop through these two lists at once? I am looking for the correct syntax to do the below foreach itemA, itemB in ListA, ListB { Console.WriteLine(itemA.ToString()+","+itemB.ToString()); } do you think this is possible in C#? And if it is, what is the lambda expression...

How do I convert a List(Of T) to an ObservableCollection(Of T) in VB.NET?

Is there a way to do this without iterating through the List and adding the items to the ObservableCollection? ...

Get a List from a List

Hi, I have 3 classes public class Item { ... } public class Order { public List Items ... } public class Customer { public List Orders ... } Now, using LINQ I need to get all items that a customer bought. How can I? I tried something like var items = from o in cust.Orders select o.Items; but result is IEnuberable> and I wanna just one...

Map two lists into one single list of dictionaries

Imagine I have these python lists: keys = ['name', 'age'] values = ['Monty', 42, 'Matt', 28, 'Frank', 33] Is there a direct or at least a simple way to produce the following list of dictionaries ? [ {'name': 'Monty', 'age': 42}, {'name': 'Matt', 'age': 28}, {'name': 'Frank', 'age': 33} ] ...

C# - Dumping a list to a dropdownlist

List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here, then sorted: nameList.Sort(); Now i need to drop it into the dropdownlist, which is where I'm having issues (using foreach): foreach (string name in nameList){ ddl.Items.Add(new ListItem(nameList[name].ToString())); } No...

C# - Sorting a list when it has more than one value per 'row' ?

Exception: Failed to compare two elements in the array. private void assignNames(DropDownList ddl, Hashtable names) { List<ListItem> nameList = new List<ListItem>(); if (ddl != null) { ddl.ClearSelection(); ddl.Items.Add(new ListItem("Select Author")); foreach (string key in names.Keys) { ...

If object is Generic List

Is there any way to determine if an object is a generic list? I'm not going to know the type of the list, I just know it's a list. How can I determine that? ...

Sorting list of URLs by length in Jython

Hi, I am writing a Jython script to sort a list of URLs. I have a list that looks like this: http://www.domain.com/folder1/folder2/|,1 http://www.domain.com/folder1/|,1 http://www.domain.com/folder1/folder2/folder3/|,1 http://www.domain.com/folder1/|,1 http://www.domain.com/folder1/folder2/|,1 http://www.domain.com/folder1/folder2/|,1...

How do I initialize two lists at the same time with ajax?

Hi does anybody know how to initialize two list at the same time with ajax? This is my code <html> <body onload="iniciaListas()"> <script type="text/javascript"> var xmlHttp function iniciaListas() { muestraListaPaises(); muestraListaProfesiones(); } function muestraListaProfesiones() { //Se inicializa el objeto ajax par...