Re:More Itertools
by benkuykendall on Monday May 27, 2024 @10:45PM
(#40496874)
My favorite function here is more_itertools.one. Especially in something like a unit test, where ValueErrors from unexpected conditions are desirable, we can use it to turn code like
into
I guess you could also use tuple-unpacking:
But the syntax is awkward to unpack a single item. Doesn't that trailing comma just look implausible? (Also I've worked with type-checkers that will complain when a tuple-unpacking could potentially fail, while one has a clear type signatures Iterable[T] -> T.)
[ Parent
| on HN ]
You can also do
[result] = get_some_stuff(...)
Re:More Itertools
by adammarples on Tuesday May 28, 2024 @06:20AM
(#40499191)
Do tuple unpacking like this
result, _* = iterable()