nested-lists

LINQ: How to join nested Lists in an ObjectCollection

半世苍凉 提交于 2020-08-24 10:48:25
问题 is it possible to define a LINQ statement for the following problems WITHOUT using a foreach loop? public class GroupObject { public String name; public List<String> letters; public void test() { List<GroupObject> myGroups = new List<GroupObject> { new GroupObject { name="test1", letters=new List<String>{"x","y","z"} }, new GroupObject { name="test2", letters=new List<String>{"l","m","n"} }, new GroupObject { name="test3", letters=new List<String>{"m","x","z"} } }; // LINQ problem 1: how to

Testing diagonally adjacent elements in nested lists

纵然是瞬间 提交于 2020-07-08 21:33:22
问题 This is a followup to a recent question that wasn't asked clearly. The poster Aditi Jain's clarifications invalidate the answer somewhat that's already posted there, hence this new post. The objective is to check whether there's no diagonally adjacent pair of elements in the nested lists which are negative of one another. The poster is new to Haskell programming. The function signature is: checkNegation :: [[Int]] -> Bool Examples: checkNegation [[1,2], [-2,3]] will return False : [ [ 1 , 2],

Testing diagonally adjacent elements in nested lists

安稳与你 提交于 2020-07-08 21:29:25
问题 This is a followup to a recent question that wasn't asked clearly. The poster Aditi Jain's clarifications invalidate the answer somewhat that's already posted there, hence this new post. The objective is to check whether there's no diagonally adjacent pair of elements in the nested lists which are negative of one another. The poster is new to Haskell programming. The function signature is: checkNegation :: [[Int]] -> Bool Examples: checkNegation [[1,2], [-2,3]] will return False : [ [ 1 , 2],

Testing diagonally adjacent elements in nested lists

a 夏天 提交于 2020-07-08 21:28:56
问题 This is a followup to a recent question that wasn't asked clearly. The poster Aditi Jain's clarifications invalidate the answer somewhat that's already posted there, hence this new post. The objective is to check whether there's no diagonally adjacent pair of elements in the nested lists which are negative of one another. The poster is new to Haskell programming. The function signature is: checkNegation :: [[Int]] -> Bool Examples: checkNegation [[1,2], [-2,3]] will return False : [ [ 1 , 2],

Printing name of second lowest mark scorer in a nested list and arranging in alphabetical order in Python

99封情书 提交于 2020-06-29 05:13:01
问题 if __name__ == '__main__': arr = [] for _ in range(int(input())): name = input() arr.append(name) score = float(input()) arr.append(score) array = [arr[i:i+2] for i in range(0, len(arr), 2)] marks = [] for j in range(0, len(array)): marks.append(array[j][1]) marks = list(map(float, marks)) marks.sort() seclow = marks[1] for k in range(0, len(array)): if (seclow == float(array[k][1])): print(array[k][0]) **SAMPLE INPUT:** 5 Harry 37.21 Berry 37.21 Tina 37.2 Akriti 41 Harsh 39 **EXPECTED OUTPUT

Remove sublist duplicates including reversed

夙愿已清 提交于 2020-06-06 08:21:13
问题 For example i have following list = [['1', '2'], ['1', '3'], ['1', '4'], ['1', '5'], ['2', '1'], ['4', '1'], ['2', '6']] I want to match if a sub list has a reversed sub list within same list (i.e. ['1', '2'] = ['2', '1']) , and if True than to remove from the list the mirrored one. The final list should look like : list = [['1', '2'], ['1', '3'], ['1', '4'], ['1', '5']['2', '6']] This is what i tried: for i in range(len(list)): if list[i] == list[i][::-1]: print("Match found") del list[i][::

How to remove the innermost level of nesting in a list of lists of varying lengths

久未见 提交于 2020-03-14 19:06:17
问题 I'm trying to remove the innermost nesting in a list of lists of single element length lists. Do you know a relatively easy way (converting to NumPy arrays is fine) to get from: [[[1], [2], [3], [4], [5]], [[6], [7], [8]], [[11], [12]]] to this?: [[1, 2, 3, 4, 5], [6, 7, 8], [11, 12]] Also, the real lists I'm trying to do this for contain datetime objects rather than ints in the example. And the initial collection of lists will be of varying lengths. Alternatively, it would be fine if there