You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fact that split_after_first returns either one or two lists makes it awkward to interpret its results in some cases. Consider:
>>> a, *b = split_after_first([1,2,3,4,5], lambda x: x == 5)
>>> a, b
([1, 2, 3, 4, 5], [])
>>> a, *b = split_after_first([1,2,3,4,5], lambda x: x == 6)
>>> a, b
([1, 2, 3, 4, 5], [])
Both of these calls produce identical results. In the first one, though, the predicate actually found a match, while in the second one it didn't. So if I'm trying to distinguish between a) only the last input value matching the predicate and b) no input values matching the predicate, I have to further examine the contents of the returned list. I.e. I can't easily know if it actually did "split after" or just didn't split at all.
If split_after_first() instead returned two lists all the time - one containing everything up to the first match (if there is one!), and the second containing everything else - then I'd always know how splitting occurred. That is:
>>> a, b = split_after_first([1,2,3,4,5], lambda x: x == 5)
>>> a, b
([1, 2, 3, 4, 5], [])
>>> a, b = split_after_first([1,2,3,4,5], lambda x: x == 6)
>>> a, b
([], [1, 2, 3, 4, 5])
I guess changing the API entirely is probably not a good idea. But could we add an argument to split_after_first which enables behavior like this? E.g.:
>>> a, b = split_after_first([1,2,3,4,5], lambda x: x == 6, explicit=True)
>>> a, b
([], [1, 2, 3, 4, 5])
The text was updated successfully, but these errors were encountered:
The fact that split_after_first returns either one or two lists makes it awkward to interpret its results in some cases. Consider:
Both of these calls produce identical results. In the first one, though, the predicate actually found a match, while in the second one it didn't. So if I'm trying to distinguish between a) only the last input value matching the predicate and b) no input values matching the predicate, I have to further examine the contents of the returned list. I.e. I can't easily know if it actually did "split after" or just didn't split at all.
If split_after_first() instead returned two lists all the time - one containing everything up to the first match (if there is one!), and the second containing everything else - then I'd always know how splitting occurred. That is:
I guess changing the API entirely is probably not a good idea. But could we add an argument to split_after_first which enables behavior like this? E.g.:
The text was updated successfully, but these errors were encountered: