4 ms·
Can't comment on C++11 but the Python version is better written as: type = "foo" try: target_widget = (x for x in widgets if x.get_type() == ty
by reinhardt 14y ago
Can't comment on C++11 but the Python version is better written as:
type = "foo"
try:
target_widget = (x for x in widgets if x.get_type() == type).next()
print "widget found:",target_widget
except StopIteration:
print "widget not found"
- kzrdude 14y agoYou can also use the `next(x for x in ...)` form where you can even supply a default value.