list

Python: Slicing a list into n nearly-equal-length partitions

I'm looking for a fast, clean, pythonic way to divide a list into exactly n nearly-equal partitions. partition([1,2,3,4,5],5)->[[1],[2],[3],[4],[5]] partition([1,2,3,4,5],2)->[[1,2],[3,4,5]] (or [[1,2,3],[4,5]]) partition([1,2,3,4,5],3)->[[1,2],[3,4],[5]] (there are other ways to slice this one too) There are several answers in here h...

Isn't an Iterator in c++ a kind of a pointer?

Ok this time I decided to make a list using the STL. I need to create a dedicated TCP socket for each client. So everytime I've got a connection, I instantiate a socket and add a pointer to it on a list. list<MyTcp*> SocketList; //This is the list of pointers to sockets list<MyTcp*>::iterator it; //An iterator to the list of pointers ...

Using a Loop to add objects to a list(python)

Hey guys so im trying to use a while loop to add objects to a list. Heres bascially what i want to do: (ill paste actually go after) class x: blah blah choice = raw_input(pick what you want to do) while(choice!=0): if(choice==1): Enter in info for the class: append object to list (A) if(choice==2):...

Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] to [x0 x1 x2]?

I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0]...

Linq filtering an IQueryable<T> (System.Data.Linq.DataQuery) object by a List<T> (System.Collection.Generic.List) object?

My IQueryable line is: // find all timesheets for this period - from db so System.Data.Linq.DataQuery var timesheets = _timesheetRepository.FindByPeriod(dte1, dte2); My List line is: // get my team from AD - from active directory so System.Collection.Generic.List var adUsers = _adUserRepository.GetMyTeam(User.Identity.Name); I ...

How to get list of declared functions with their data from php file?

I need to get list of functions with their contents (not only the function name) from php file. I tried to use regex but it has lots of limitations. it doesn't parse all types of functions. for example it fails if the function has if and for loop statements. in details: I have around 100 include files. each file has number of declared f...

Use BDC column in list as multi-select column in sharepoint 2010

how to Use BDC column in list as multi-select column in sharepoint 2010 ...

Latex: Listing all figures (tables, algorithm) once again at the end of the document

Hi all, I have been writhing a rather large document with latex. Now I would like to list all the figures / tables / algortihms once again at the end of the file so that I can check if they all look the same. For example, if every algorithm has the same notation. How can I do this? I know about \listofalgorithms and \listoffigures b...

How do I use xStream to output Java Objects with List properties?

Hello, I am trying to output some Java objects as JSON, they have List properties which I want to be formatted as { "People" : [ { "Name" : "Bob" } , { "Name" : "Jim" } ] } However, I cannot figure out how to do this with XStream. It always outputs as { "Person" : { "Name" : "Bob" }, "Person" : { "Name" : "Bob" } Is there a way to fi...

Styling a result set

Perhaps this is not the proper place to ask this question, if that is the case, please direct me to the correct venue. I'm looking for research, guides, any kind of information pertaining to the structuring and styling of results sets; data which comes back from a search, or when looking at content in a list view. Links would be apprec...

Should xml represent a set or a list?

I always think of xml like a set data structure. Ie: <class> <person>john</person> <person>sarah</person> </class> Is equivalent to: <class> <person>sarah</person> <person>john</person> </class> Question One: Are these two things logicly equivalant? Are you allowed to make things like this in xml? <methodCall> <param>h...

F# Active Pattern List.filter or equivalent

I have a records of types type tradeLeg = { id : int ; tradeId : int ; legActivity : LegActivityType ; actedOn : DateTime ; estimates : legComponents ; entryType : ShareOrDollarBased ; confirmedPrice: DollarsPerShare option; actuals : legComponents option ; type trade = { id : int ; securityId ...

Easy way to check if item is in list?

Hey guys, I'm writing a search algorithm in C++, and one of the things I need to do is have a few if statements that check cells above, below, left of, and right of. Each time a cell is found to be open and added to the stack, I want it added to a list of cells already checked. I want to be able to say in the if statement if(thisCell ...

Question about a C macro expansion in Linux Kernel code

I generally have ignored using macros while writing in C but I think I know fundamentals about them. While i was reading the source code of list in linux kernel, i saw something like that: #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name) (You can access the re...

mysql check if numbers are in a comma separated list

Hi I have a table like this: UID(int) NUMBERS(blob) ---------------------- 1 1,13,15,20 2 3,10,15,20 3 3,15 And I would like to test if 3 and 15 are in the blob called NUMBERS. And can see the LIKE %% cannot be used Only row with ID 2 and three scoulb be selected... ...

Removing duplicates without overriding hash method

Hello, I have a List which contains a list of objects and I want to remove from this list all the elements which have the same values in two of their attributes. I had though about doing something like this: List<Class1> myList; .... Set<Class1> mySet = new HashSet<Class1>(); mySet.addAll(myList); and overriding hash method in Class1...

Elegent way to collapse or expand sub-sequences of a list in Python?

I want to collapse or expand sub-sequences of a list e.g. ['A', 'B', 'D', 'E', 'H'] -> ['AB', 'DE', 'H'] and vice versa EDIT: the example above may cause misunderstanding. the following is better: e.g. ['foo', 'bar', 'wtf'] <-> ['baz', 'wtf'] currently I wrote some ugly code like: while True: for i, x in enumerate(s): if x ==...

Populating PHP list() with values in an array.

Hi, I have an array: $arr = array('foo', 'bar', 'bash', 'monkey', 'badger'); I want to have the elements in that array appear as the variables in my list(): list($foo, $bar, $bash, $monkey, $badger) = $data; Without actually specifying the variables, I tried; list(implode(",$", $arr)) = $data; and list(extract($arr)) = $data; B...

Generating a List Class in Python

I am having some problems generating a list for a class in Python. I know there is something simple I'm overlooking, but I just can't figure it out. My basic code so far: class Test: def __init__(self,test): self.__test = test My problem is that if I enter t = Test([1,3,5]) things will work just fine, but if I add t...

Handle Union of List in C# with duplicates

Hi, I am trying to understand how to handle union or merge of two lists that can have duplicates. For example, List1 has { A, B, C} and List2 has { B, C, D }. I tried to use the Union operation and got a new list with values (A, B, C, D}. However, I need the B & C values from the second list, not first one. Is there a way to specify the ...