Closed Mr-Xcoder closed 6 years ago
That will raise a TypeError if array
isn't iterable.
To fix that and avoid going twice through the array, the function could simply do this:
def split_once(array, needle):
array = iterable(array, make_digits = True)
index = index_of(array, needle)
return [array[0 : index - 1], array[index :]] if index else [array]
Previously,
œṡ
had a weird behaviour if y didn't occur in x. That is, it discarded the last element and wrapped the result in a list along with an empty list at the end (i.e.[x[:-1], []]
). Now, it just returns[x]
, which seems more intuitive. Let me know if this causes any issues / the old behaviour is intended.