Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-185

Typed Edges Count

Problem

Count the edges of each type in a typed edge list.

edges is a list of [u, v, type] triples where type is a string. Return a dictionary mapping each type to its number of edges; an empty edge list yields an empty dictionary.

Hint

Edge type histograms are the simplest summary of a heterogeneous graph.

Test cases

case 1
in: [[[0,1,"follow"],[1,2,"follow"],[2,0,"like"]]]
expected: {"follow":2,"like":1}
case 2
in: [[]]
expected: {}
case 3
in: [[[0,1,"a"],[0,1,"b"],[1,2,"a"]]]
expected: {"a":2,"b":1}
Starter codePython
def typed_edges_count(edges):
    # Your code here
    pass

3 test cases · run your code against them in the editor