answered 11 years ago
Try replacing
for j in range(len(fw)):
with
for j in fw.keys():
(In your code, fw is not a list, but a finite family, so its entries are not indexed by 0, 1, 2, ..., necessarily.)
fw