On 30.10.2017 9:29, python-ideas-request@python.org wrote:
If I have understood your use-case, you have a function that returns aCorrect.
list of results (or possibly an iterator, or a tuple, or some other
sequence):
print(search(haystack, needle))
# prints ['bronze needle', 'gold needle', 'silver needle']
There are times you expect there to be a single result, and if there are
multiple results, that is considered an error. Am I correct so far?
If so, then sequence unpacking is your friend:That works. Too arcane in my book though (and others' too according to https://stackoverflow.com/a/47
result, = search(haystack, needle)
<...>
I *think* this will solve your problem.
If not, can you please explain what "single()" is supposed to do, why it
belongs in itertools, and show an example of how it will work.
3337/648265 ), and the error messages are cryptic in this use case.
It also cannot be a part of an expression, unlike next().
The initial post on the above link summarizes the suggested implementation pretty well.
--
Regards,
Ivan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/