将列表理解转换为 for 循环

Convert list comprehension to for loop

this Huffman code 上,我找到了下面的代码。

heap = [[wt, [sym, ""]] for sym, wt in symb2freq.items()]

是否可以将这种列表压缩转换为 for 循环?

这对我有用

heap = [[wt, [sym, ""]] for sym, wt in enumerate(symb2freq.items())]

是的,您可以:

heap = []
for sym, wt in symb2freq.items():
    heap.append([wt, [sym, ""]])