list

Faster way to do a List<T>.Contains()

I am trying to do what I think is a "de-intersect" (I'm not sure what the proper name is, but that's what Tim Sweeney of EpicGames called it in the old UnrealEd) // foo and bar have some identical elements (given a case-insensitive match) List‹string› foo = GetFoo(); List‹string› bar = GetBar(); // remove non matches foo = foo.Where(x ...

Python - Intersection of two lists

Hi, I know how to get an intersection of two flat lists: b1 = [1,2,3,4,5,9,11,15] b2 = [4,5,6,7,8] b3 = [val for val in b1 if val in b2] or def intersect(a, b): return list(set(a) & set(b)) print intersect(b1, b2) But when I have to find intersection for nested lists then my problems starts: c1 = [1, 6, 7, 10, 13, 28, 32, ...

Python - list transformation

Hello, Does anyone knows what magic I have to use to change x list: x = [1,2,3,4,5,11] into y list? y = ['01','02','03','04','05','11'] Thank you all in advance for helping me... ...

How do I get an item in a List<> based on an integer field?

I have a List<> in my program, filled with my custom class. I want to be able to extract an object from the list by simply specifying an integer, then returning all objects that have an integer property set to that integer. I was thinking of doing it like this: int exampleint = 5; List<MyClass> extract = new List<MyClass>(); for(int i =...

List of Structs or Dataset in C#?

I have some data I want to work with. Two string and two numbers and I have say 8000 rows of data. Is a dataset the best option here to use, or could I use a struct and have a list of structs? Would there be much performance difference between the list and the dataset? ...

What is the best practice for readonly lists in NHibernate

Hello, Domain Model I am working on has root aggregate and child entities. Something like the following code: class Order { IList<OrderLine> Lines {get;set;} } class OrderLine { } Now I want my Order to control lines. Something like that: class Order { OrderLine[] Lines {get;} void AddLine(OrderLine line); } At this tim...

Python: How to get last 9 items of a list?

I need the last 9 numbers of a list and I'm sure there is a way to do it with slicing but I can't seem to get it. I can get the first 9: num_list[0:9] Any help would be great. Thanks in advance :) ...

F# convert Array2 into a list

I'm still new to functional programming so if I can't figure out how to do something I revert back to procedural style. I found a way to get around having to convert to a list but I'd still like to know how. Here is my attempt to convert a two dimensional array to a list. let board = Array2.init 10 20 (fun i j -> pull(i, j)) let muta...

How to make a list comprehension with the group() method in python?

Hi, I'm trying to write a little script to clean my directories. In fact I have: pattern = re.compile(format[i]) ... current_f.append(pattern.search(str(ls))) and I want to use a list comprehension but when I try: In [25]: [i for i in current_f.group(0)] I get: AttributeError: 'list' object has no attribute 'group' So how to ma...

Best animation to show addition/removal of list element

What is the best way to communicate visually that an element has been added to or removed from a list of items? (I'm going for usability, not gratuitous eye candy) Slide the other items up or down to show the new item or hide the deleted item Fade items in or out, but do not animate the other items A combination of #1 and #2 No animat...

Do Python lists have an equivalent to dict.get?

I have a list of integers. I want to know whether the number 13 appears in it and, if so, where. Do I have to search the list twice, as in the code below? if 13 in intList: i = intList.index(13) In the case of dictionaries, there's a get function which will ascertain membership and perform look-up with the same search. Is there ...

How to do padding inside <mx:List>?

I have list for which I require some space between the items and the list margin. The items inside the list are rendered from some other file. But when I add padding I cannot see any difference. Something like this: <mx:List id="List" selectionColor="red" itemRenderer="renderers.List" doubleClick="Handler()" width="500" corn...

Python - Acquire value from dictionary depending on location/index in list

Hi Everybody, From MySQL query I get data which I put into a dictionary "d": d = {0: (datetime.timedelta(0, 25200),), 1: (datetime.timedelta(0, 25500),), 2: (datetime.timedelta(0, 25800),), 3: (datetime.timedelta(0, 26100),), 4: (datetime.timedelta(0, 26400),), 5: (datetime.timedelta(0, 26700),)} I have a list "m" with...

Loading a lookup table from a database into a C# program - data structure?

I have a table full of id's,categories and weights that I need to reference in my program as I read in records that contain those categories. What is the most efficient method to read those from a database and put into a structure that I can reference? The ID's (and possibly the names) would be unique Data might look like: ID,Category...

Search for an item in a Lua list

If I have a list of items like this: local items = { "apple", "orange", "pear", "banana" } how do I check if "orange" is in this list? In Python I could do: if "orange" in items: # do something Is there an equivalent in Lua? ...

Best way to rearrange an ArrayList in Java

What is the best way to rearrange elements in an list? I need the ability to move elements to move elements in the list, one step back or forward in the index. I was thinking of getting the index of the item, adding it at index -1 / +2 and removing the old reference. Is there a faster way to handle rearranging without creating duplicat...

Java: What is the best way to find elements in a sorted List?

I have a List<Cat> sorted by the cats' birthdays. Is there an efficient Java Collections way of finding all the cats that were born on January 24th, 1983? Or, what is a good approach in general? ...

What's wrong in terms of performance with this code? List.Contains, random usage, threading?

I have a local class with a method used to build a list of strings and I'm finding that when I hit this method (in a for loop of 1000 times) often it's not returning the amount I request. I have a global variable: string[] cachedKeys A parameter passed to the method: int requestedNumberToGet The method looks similar to this: List...

Are 2 dimensional Lists possible in c#?

Hello, I'd like to set up a multidimensional list. For reference, I am working on a playlist analyzer. I have a file/file-list, which my program saves in a standard list. One line from the file in each list entry. I then analyze the list with regular-expressions to find specific lines. Some of the data/results from the lines needs to b...

Extract array from list in python

If I have a list like this: >>> data = [(1,2),(40,2),(9,80)] how can I extract the the two lists [1,40,9] and [2,2,80] ? Of course I can iterate and extract the numbers myself but I guess there is a better way ? ...