list

How can I create an array/list of dictionaries in python?

I have a dictionary as follows: {'A':0,'C':0,'G':0,'T':0} I want to create an array with many dictionaries in it, as follows: [{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},...] This is my code: weightMatrix = [] for k in range(motifWidth): weightMatrix[k] = {'A':0,'C':0,...

Equals method of System.Collections.Generic.List<T>...?

I'm creating a class that derives from List... public class MyList : List<MyListItem> {} I've overridden Equals of MyListItem... public override bool Equals(object obj) { MyListItem li = obj as MyListItem; return (ID == li.ID); // ID is a property of MyListItem } I would like to have an Equals method in the MyList objec...

In python, what does len(list) do?

My doubt is that if the len(list) calculates the length of the list everytime it is called or it returns the value of the builtin counter.I have a context where i need to check the length of list everytime in a loop, likelistData = [] for value in ioread(): if len(listData)>=25: processlistdata() clearlistdata() l...

Deserializing a class containing a List<T>: Why is List initially filled with Nulls?

I have a class Bar which contains a List<Foo>, with both Foo and Bar implementing ISerializable. When deserializing a Bar, the List<Foo> is initially filled with (the correct number of) nulls; then on exiting the Bar deserialization ctor, each Foo's deserialization ctor is called, filling the List<Foo> with the (correctly deserialized)...

Efficient intersection of two List<String> in Java?

Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew = DBUtils.GetColumns(db, TableName); And I need to get the intersection of these. Is there a quick way to achieve this? ...

Python - Differences between elements of a list

Given a list of numbers how to find differences between every (i)-th and (i+1)-th of its elements? Should one better use lambda or maybe lists comprehension? Example: Given a list t=[1,3,6,...] it is to find a list v=[2,3,...] because 3-1=2, 6-3=3, etc. ...

Python - Initializing Multiple Lists/Line

This is terribly ugly: psData = [] nsData = [] msData = [] ckData = [] mAData = [] RData = [] pData = [] Is there a way to declare these variables on a single line? ...

SPPersistedObject and List<T>

Hi I want sharepoint to "persist" a List of object I wrote a class SPAlert wich inherit from SPPersistedObject : public class SMSAlert: SPPersistedObject { [Persisted] private DateTime _scheduledTime; [Persisted] private Guid _listId; [Persisted] private Guid _siteID; } Then I wrote a...

Generic Lists c#

Is the following at all possible in c#? I have the following but the last line won't compile, am i missing something? public static void BuildGeneric<T>(List<T> l) { l = new List<T>(); var anything = new object(); l.Add(anything); } "The best overloaded method match for 'System.Collections.Generic.List.Add(T)' has some in...

LinkedHashMap vs HashMap != LinkedList vs ArrayList

I have read that LinkedHashMap has faster iteration speed than HashMap because its elements are doubly linked to each other. Additionally, because of this, LinkedHashMap is slower when inserting or deleting elements. Presumably because these links also need to be updated. Although I can see an analogy to LinkedList vs ArrayList, in that...

How to combine elements of a list

I'm working in c#. I have a sorted List of structures. The structure has a DateTime object which stores month and year and an integer which stores a value. The list is sorted by date. I need to traverse the list and combine it so that I only have one instance of the structure per date. For example: My initial list would look like this:...

Python: Indexing list for element in nested list

I know what I'm looking for. I want python to tell me which list it's in. Here's some pseudocode: item = "a" nested_list = [["a", "b"], ["c", "d"]] list.index(item) #obviously this doesn't work here I would want python to return 0 (because "a" is an element in the first sub-list in the bigger list). I don't care which sub-element...

Appropriate collection for variable-depth list?

If I wanted to have a collection that described the (recursive) contents of a root directory, including directories and files, how would I store them? Or do I need to come up with an object that holds: -Current directory -Parent directory -Files in directory ..and slap them all in one big list and manually work out the relationship at r...

Python - merge items of two lists into a list of tuples

What's the pythonic way of achieving the following? list_a = [1, 2, 3, 4] list_b = [5, 6, 7, 8] #Need to create a of tuples from list_a and list_b list_c = [(1,5), (2,6), (3,7), (4,8)] Each member of list_c is a tuple, whose first member is from list_a and the second is from list_b. ...

Python - file contents to nested list

Hi All, I have a file in tab delimited format with trailing newline characters, e.g., 123 abc 456 def 789 ghi I wish to write function to convert the contents of the file into a nested list. To date I have tried: def ls_platform_ann(): keyword = [] for line in open( "file", "r" ).readlines(): for value in line....

Get the first few elements from List on C#

I have List with n items. I wish transform my list to new list, in which no more than n first items. Example for n=3: [1, 2, 3, 4, 5] => [1, 2, 3] [1, 2] => [1, 2] What is the shortest way to do this? ...

List<T>.Sort sorting nulls incorrectly

I have a list of objects, some of which can be null. I want it sorted by some property, with nulls at the end of list. However, List<T>.Sort() method seems to put nulls in the beginning no matter what the comparer returns. This is a little program that I used to test this: class Program { class Foo { public int Bar; public Foo(...

How to have multiple views for sharepoint documents?

I have a sharepoint with a lot of documents stored in it. I would like to have different views for these documents. One view would be by "project" to see all related project documents, another view would be "Design Documents" to view all design documents across all projects. Is there a way to do list so that there is only 1 copy of the d...

List of Dicts comparision to match between lists and detect value change in python

I have a list of dictionaries that I get back from a web service call. listA = [{'name':'foo', 'val':'x'}, {'name':'bar', 'val':'1'}, {'name':'alice','val':'2'}] I need to compare results from the previous call to the service and pull out changes. so on next call I may get: listB = [{'name':'foo', 'val':'y'}, ...

jquery sortable lists with dynamically generated list ids

For my webpage, I have a number of lists which I'm generating dynamically from the database. Each list is generated like so: <ul id = "<%= "subgroups_for_tumourgroup_" + item.ID %>"> I'm trying to make them sortable using jquery's sortable list <script type="text/javascript"> $(function() { $('#subgroups_for_tumourgroup_1')...