[Solved] Javascript – print all names in array containing multiple objects [closed]

Extract only the students with grade 80 or higher with Array.filter. Map the remaining students into a new format using Array.map. Result: let students = [{ fname: “Jane”, lname: “Brazier”, snum: “100366942”, agrade: 67.59127376966494, tgrade: 64.86530868914188, egrade: 70.52944558104066 }, { fname: “Ricardo”, lname: “Allen”, snum: “100345641”, agrade: 65.80370345301014, tgrade: 75.40211705841241, egrade: 55.39348896202821 }, { fname: … Read more

[Solved] Display a map of two vectors

There could be gundreds of way to do that. Here is one: template<class T> void dumpVector( const std::vector<T>& vect ) { for ( std::vector<T>::const_iterator iter = vect.begin(); iter != vect.end(); ++iter ) { std::cout << ” ” << *iter; } } for ( std::map<vector<double>,vector<int>>::const_iterator mapIter = path.begin(); mapIter != path.end(); ++mapIter ) { std::cout << … Read more

[Solved] Python List of Dictionaries by Loops

If you want only print the resulting dictionaries, uncomment the print statement (and comment the following 2). d1 = [ {‘index’:’1′,’color’:’red’}, {‘index’:’2′,’color’:’blue’}, {‘index’:’3′,’color’:’green’} ] d2 = [ {‘device’:’1′,’name’:’x’}, {‘device’:’2′,’name’:’y’}, {‘device’:’3′,’name’:’z’} ] result_list = [] for dict1 in d1: merged_dict = dict1.copy() for dict2 in d2: merged_dict.update(dict2) # print(merged_dict) result_list.append(merged_dict.copy()) print(result_list) The result: [{‘name’: ‘x’, ‘device’: … Read more

[Solved] Merge multiple list of dict with same value in common key [closed]

If you want a more pythonic way: from itertools import groupby from pprint import pprint from collections import ChainMap a = [{‘a’:0,’b’:23}, {‘a’:3,’b’:77}, {‘a’:1,’b’:99}] b = [{‘a’:1,’c’:666}, {‘a’:4,’c’:546}] c = [{‘d’:33,’a’:3}, {‘d’:1111,’a’:4}, {‘d’:76,’a’:1}, {‘d’:775,’a’:0}] d = [{‘a’:2,’e’:12}, {‘a’:4,’e’:76}] dict_list = a + b + c + d # You just need to specify the key … Read more

[Solved] How to map dict into another dict Python

You can use a defaultdict as follow: class Account: def __init__(self, x, y): self.x = x self.y = y d_in = {0: Account(13, 1), 1: Account(15, 5), 2: Account(55, 1), 3: Account(33 ,1)} d_out = collections.defaultdict(list) for index, k in enumerate(d_in.keys()): d_out[d_in[k].y].append(index) print d_out Giving the following output: defaultdict(<type ‘list’>, {1: [0, 2, 3], 5: … Read more

[Solved] Convert flat list to dictionary with keys at regular intervals [closed]

Here’s a straightforward solution with a simple loop: dict_x = {} for value in list_x: if isinstance(value, str): dict_x[value] = current_list = [] else: current_list.append(value) Basically, if the value is a string then a new empty list is added to the dict, and if it’s a list, it’s appended to the previous list. solved Convert … Read more

[Solved] How to unmarshal struct into map in golang [closed]

Here is an example with marshal and unmarshal using your object definition package main import ( “encoding/json” “fmt” ) type MyObject struct { ID string `json:”id”` Name string `json:”name”` Planets map[string]int `json:”planets”` } func main() { aa := &MyObject{ ID: “123”, Name: “pepe”, Planets: map[string]int{ “EARTH”: 3, “MARS”: 4, }, } // Marshal out, err … Read more

[Solved] How to compare list values in a dictionary

If you want to compare keys of Dictionary, then: var dict1 = new Dictionary<string, List<string>>(); var dict2 = new Dictionary<string, List<string>>(); // something.. if (dict1.Keys.SequenceEqual(dict2.Keys)) { // your code } If you want to compare values of Dictionary, then: var dict1 = new Dictionary<string, List<string>>(); var dict2 = new Dictionary<string, List<string>>(); // something.. var d1Keys … Read more