I know that "".join(list) converts the list to a string, but what if that list contains a nested list? When I try it returns a TypeError due to unexpected list type. I'm guessing it's possible with error handling, but so far my attempts have been fruitless.
You could try something like this:
''.join(''.join(inner) for inner in outer)
That should work, and won't have too much trouble if the outer list contains both Strings and Lists inside of it, ''.join(myString) -> myString.
Well, if the list is nested, simply flatten it beforehand:
>>> import itertools
>>> lst = [['a', 'b'], ['c', 'd']]
>>> ''.join(itertools.chain(*lst))
'abcd'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With