Group Group Group Group Group Group Group Group Group

Chapter 5: Confusion Matrix visualization

Hi all,

I’m new at Python, thus I’m not very familiar with its syntax yet. I just want to confirm in the confusion matrix visualization part of the, in function compute_confusion_matrix(metrics, labels) there is this code snippet:

label_to_index = {l:i for i,l in enumerate(labels)}

Is this some sort of “list comprehension” syntax? So it’s possible to use list comprehension to create not only list but also dictionary?

Thanks,
chalkdust

Correct, it’s a so-called “dictionary comprehension”. Same idea as a list comprehension, except it makes a dictionary. :smile:

1 Like

Gotcha! Thanks hollance! :+1: