Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A better way: varname = (x for x in l if predicate_with_single_truth_value(x)).next()


That avoids the construction of the list, but doesn't check that the sequence only contains one value, which was the point of the example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: