在 Python 中反转键值的 for 循环是什么语法?

What syntax does this for loop that reverses the key value follow in Python?

dict_list={"a":1,"b":2,"c":3}
inverse_dict=dict([val,key] for key,val in dict_list.items())

我学过的for循环语句都是以for开头的。不明白为什么这个语句的关键字for前面有一个列表,也不知道这个语句怎么可以反转字典的键值对

inverse_dict = dict([val, key] for key, val in dict_list.items())
                    #---generator expression-------------------#
                    #--pair--#

依靠 dict() accepting an iterable of pairs to turn into a dictionary; the whole (x for y in z) production is a generator expression 产生一个可迭代对象。

在表达式中,[val, key] 表达式为 items 中的每一对形成一个 key-value 对。
(使用元组 ((val, key)) 而不是列表会更惯用。)

这句话的现代成语是字典理解,读起来更清楚:

dict_list = {"a": 1, "b": 2, "c": 3}
inverse_dict = {val: key for key, val in dict_list.items()}