I have two lists:
a = [1,2,3]
b = ["a","b","c"]
my list l is:
l = [a,b].flatten
so l = [1,2,3,"a","b","c"]
I’m looking for an elegant way of splitting the list by the type of the items in it, in order to have a and b restored as they were.
I could go with each item in the list and test, but that doesn’t seem efficient runtime-wise nor code-wise.
You could use
group_byand then pull your arrays out of the resulting Hash:If you know that you only have Fixnums and Strings then you could use
partition: