Filtering lists using LINQ

Have a look at the Except method, which you use like this: var resultingList = listOfOriginalItems.Except(listOfItemsToLeaveOut, equalityComparer) You’ll want to use the overload I’ve linked to, which lets you specify a custom IEqualityComparer. That way you can specify how items match based on your composite key. (If you’ve already overridden Equals, though, you shouldn’t need … Read more

Create a dictionary by zipping together two lists of uneven length [duplicate]

Use itertools.cycle to cycle around to the beginning of L2: from itertools import cycle dict(zip(L1, cycle(L2))) # {‘A’: ‘1’, ‘B’: ‘2’, ‘C’: ‘3’, ‘D’: ‘1’, ‘E’: ‘2’} In your case, concatenating L2 with itself also works. # dict(zip(L1, L2 * 2)) dict(zip(L1, L2 + L2)) # {‘A’: ‘1’, ‘B’: ‘2’, ‘C’: ‘3’, ‘D’: ‘1’, ‘E’: … Read more

Find the most occurring number in a List

How about: var most = list.GroupBy(i=>i).OrderByDescending(grp=>grp.Count()) .Select(grp=>grp.Key).First(); or in query syntax: var most = (from i in list group i by i into grp orderby grp.Count() descending select grp.Key).First(); Of course, if you will use this repeatedly, you could add an extension method: public static T MostCommon<T>(this IEnumerable<T> list) { return … // previous code … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)