Kumar
Kumar

Reputation: 277

In python, find minimum subject to a constraint?

How do I find the index idx, such that dist[idx] is minimum, but only amongst those whose visited[idx] is false ? The context is for an implementation of Dijkstra's algorithm.

Upvotes: 0

Views: 920

Answers (1)

jamylak
jamylak

Reputation: 133564

min((idx for idx in indexes if not visited[idx]), key=lambda idx: dist[idx])

Upvotes: 3

Related Questions