This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| type Pet struct { | |
| Owner string `json:"owner"` | |
| Pet string `json:"pet"` | |
| } | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // requires lodash.js | |
| var output = {} | |
| _.each(input, function(element){ | |
| a = _.get(output, element.owner, []) | |
| a.push(element.pet) | |
| output[element.owner] = a | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output = dict([[e["owner"], []] for e in input]) | |
| for element in input: | |
| output[element["owner"]].append(element["pet"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output = dict() | |
| for element in input: | |
| output[element["owner"]] = output.get(element["owner"], ()) + (element["pet"],) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output = dict() | |
| for element in input: | |
| item = output.get(element["owner"], []) | |
| item.append(element["pet"]) | |
| output[element["owner"]] = item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output = dict() | |
| for element in input: | |
| try: | |
| output[element["owner"]].append(element["pet"]) | |
| except KeyError: | |
| output[element["owner"]] = [element["pet"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output = {} | |
| for element in input: | |
| if output.has_key(element["owner"]): | |
| output[element["owner"]].append(element["pet"]) | |
| else: | |
| output[element["owner"]] = [element["pet"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let output = {} | |
| for (const element of input) { | |
| if (output.hasOwnProperty(element.owner)) { | |
| output[element.owner].push(element.pet) | |
| } else { | |
| output[element.owner] = [element.pet] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var output = {} | |
| input.forEach(function(element) { | |
| if (output.hasOwnProperty(element.owner)) { | |
| output[element.owner].push(element.pet) | |
| } else { | |
| output[element.owner] = [element.pet] | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var output = {} | |
| for (var i=0; i<input.length; i++) { | |
| if (output[input[i].owner] == undefined) { | |
| output[input[i].owner] = [input[i].pet] | |
| } else { | |
| output[input[i].owner].push(input[i].pet) | |
| } | |
| } |