list

Entity Framework select from link table with list

Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId Item Table: ItemId ItemName I have an 'Order' entity that has an 'Items' collection. What I need to do is return all orders that contain certain items. Example: All orders with items with id: 1, 4 and 5 (I don't care if it ha...

Clone a list of reference types that CANNOT implement ICloneable

Is there an easier/tidier way to deep clone a list of reference types that do not implement ICloneable. Currently have been looping through each object in the list like so: Dim myListCopy As New List(Of ListObj) For Each lo As ListObj In MyList myListCopy.Add(lo.ShallowCopy) Next The object ListObj contains only v...

Structure initialization as argument

I try to send some struct into STL list; struct obj { int a; int b; } list < struct obj> mylist; struct obj a = { 0, 1}; mylist.push_back ( a); Is there any other way to initialize argument of push_back? For example: mylist.push_back ( struct obj a ={0, 1}); g++ tells me: expected primary-expression before "struct"; ...

c# List<string> assignment problem

Hi, I'm fairly new to C# so this might be difficult for me to put into words. I am creating a media application and I have a class (called MediaFile) that contains information about media files (name, size, play count and tags). These are of string, double, int and List<string> types, respectively. I have a list of these objects, so fo...

Python: determine if all items of a list are the same item

In some of my code I put a series of objects in a list and I build an additional list out of their attributes, which is a string. I need to determine if all the items in this second list have the exact same value, without knowing beforehand which value it is, and return a bool so that I can do different things in my code depending on th...

Jersey JSON marshalling of empty lists

We have a Java List of objects which is marshalled via JSON which is created by Jersey. The List is called "rows". When there is data we have: {"records":"1","page":"1","total":"1","rows":[{"id":"692334","cell":["ECS","D","201009","","0","ABCD","11","11","","201009"]}]} When there is no data we have: {"page":0,"records":0,"total":...

css list inline is not listing items horizontally?

i dont know why this is not display right, the list is meant to display horizontally? instead its displaying vertically! this is my code: html file: <ul id="stats"> <li><h1>53</h1></a></li> <li><h1>67</h1></a></li> </ul> css file: #stats li { display: inline; list-style-type: none; padding-right: 20px; } ...

Piecewise list comprehensions in python

What is the easiest/most elegant way to do the following in python: def piecewiseProperty(aList): result = [] valueTrue = 50 valueFalse = 10 for x in aList: if hasProperty(x): result.append(valueTrue) else result.append(valueFalse) return result where hasProperty is some fu...

java - list question - Why did it print out -4 on the 3rd printout when i ran it?

package javaapplication8; public class Main { public static void main(String[] args) { int[] list1 = {1, 2, 3,4}; int[] list2 = {5, 6, 7,8}; for (int i = 0; i < list2.length; i++){ System.out.print(list2[i] + " "); } System.out.println(""); list2 = list1; for (int i = 0; i < list2.length;...

why i can't reverse a list of list in python

hello, i wanted to do something like this but this code return list of None (i think it's because list.reverse() is reversing the list in place): map(lambda row: row.reverse(), figure) i tried this one, but the reversed return an iterator : map(reversed, figure) finally i did something like this , which work for me , but i don't ...

Deciding between different approaches for instantiating a List<Foo> foo from fooService.getFoos()

If fooService.getFoos() returns List<Foo>. then you can write this: List<Foo> fooList = fooService.getFoos(); or this: List<Foo> fooList = new ArrayList(fooService.getFoos()); Is there any significant difference in the resulting fooList between these two approaches? ...

Can I override Python list displays?

I'd like to change the behavior of Python's list displays so that instead of producing a list, they produce a subclass of list that I've written. (Note: I don't think this is a good idea; I'm doing it for fun, not actual use.) Here's what I've done: old_list = list class CallableList(old_list): def __init__(self, *args): ...

Java: Casting from List<B> to List<A> when B implements A?

I have the following class & interface defined: public interface A { } public class B implements A { } I have a List of B objects that I need to cast to a List of A objects: List<B> listB = new List<B>(); listB.add(new B()); // dummy data listB.add(new B()); // dummy data listB.add(new B()); // dummy data List<A> listA = (List<A>...

Given a Python list, how to write a function that returns a given range of elements?

I have def findfreq(nltktext, atitem) fdistscan = FreqDist(nltktext) distlist = fdistscan.keys() return distlist[:atitem] which relies on FreqDist from the NLTK package, and does not work. The problem seems to be the part of the function where I try to return only the first n items of the list, using the variable atitem. S...

in C#, how do I order items in a list where the "largest" values are in the middle of the list

I have been stumped on this one for a while. I want to take a List and order the list such that the Products with the largest Price end up in the middle of the list. And I also want to do the opposite, i.e. make sure that the items with the largest price end up on the outer boundaries of the list. Imagine a data structure like this.. ...

Challenges of refactoring unit-tests to be maintainable and readable when dealing with List<T> objects

In the book The Art of Unit Testing it talks about wanting to create maintainable and readable unit tests. Around page 204 it mentions that one should try to avoid multiple asserts in one test and, perhaps compare objects with an overridden Equals method. This works great when we have only one object to compare the expected vs. actual re...

how to count odd and even number with using PROLOG

question is: when we key in mem([1,2,3,4,5]). we will get the output as bellow: odd=3 even=2 my coding is like that but cannot run. can help me check where is my mistake?? mem(X,[X|L]). mem(X,[element|L]):- mem([X,L]). count([],L,L). count([X|H],L1,L2):- write(even), X%2=0,nl, write(odd), X%2>=1,nl, count...

C# make a list with image and label like Messenger

Hello, How can I build on C# a a list like on Messenger where contacts appear with an image and a text with the contact's name? What components should I use to build it? Using Winforms by the way. Thanks ...

Select method in List<t> Collection

Hi, I have one asp.net application, and now i am using dataset for data manipulation. recently i started to convert this dataset to List collection. But, in some places i can't work. One is that in my old version i am using datarow[] drow = dataset.datatable.select(searchcriteria). But in List collection there is no method available for...

How to nicely output a list of separated strings ?

Usually, when I had to display a list of separated strings, I was doing something like: using namespace std; vector<string> mylist; // Lets consider it has 3 elements : apple, banana and orange. for (vector<string>::iterator item = mylist.begin(); item != mylist.end(); ++item) { if (item == mylist.begin()) { cout << *item; } ...