On this Huffman code, I found the below code.
heap = [[wt, [sym, ""]] for sym, wt in symb2freq.items()]
Is that possible to convert this kind of list compression into a for-loop?
On this Huffman code, I found the below code.
heap = [[wt, [sym, ""]] for sym, wt in symb2freq.items()]
Is that possible to convert this kind of list compression into a for-loop?
Yes, you can:
heap = []
for sym, wt in symb2freq.items():
heap.append([wt, [sym, ""]])
This works for me
heap = [[wt, [sym, ""]] for sym, wt in enumerate(symb2freq.items())]