I am know how to easily flatten a list of lists. For example:
my_list = [['abc'],[1,2,3]]
list(itertools.chain.from_iterable(my_list))
But if
my_list = ['abs',[1,2,3]]
list(itertools.chain.from_iterable(my_list))
I get ['a','b','c',1,2,3]
, while I want ['abc', 1,2,3]
I can solve this problem by running a for loop
for the second element in the original list, but that seems like a messy way to do it, and becomes really messy if you don't know which element in a list is a list, and which is a string.
Is there a simple way to flatten a list that has both lists and string in it?