Reputation: 35
edges=[
((1, 2): 9.433981132056603),
((1, 3): 18.973665961010276),
((1, 4): 0.0),
((1, 5): 82.87339742040264),
((1, 6): 29.966648127543394),
((1, 7): 0.0)
]
I have 5 items in the edges
list. How can I remove the keys (1,4)
and (1,7)
, where the value is 0?
Desired output:
edges [
((1, 2): 9.433981132056603),
((1, 3): 18.973665961010276),
((1, 5): 82.87339742040264),
((1, 6): 29.966648127543394)
]
Upvotes: 0
Views: 60
Reputation: 35
I solved it with this code:
populated = filter(lambda c: c[1] >0, Edges)
print(list(populated))
Upvotes: 1