So, I have lists of lists like following:
data = [
['foo', 'bar'],
['one', 'two']
]
And, I want to flatten these lists by alternating between two lists. So, output like
flattened = ['foo', 'one', 'bar', 'two']
I am using the list(chain.from_iterable(zip_longest(*data)))
which works fine.
But, I am trying to figure out how to handle scenarios where there are duplicates that I want to get rid of.
data = [
['foo', 'bar'],
['foo', 'two']
]
I want something like
flatted = ['foo', 'two', 'bar']
rather than ['foo', 'foo', 'bar', 'two']
How do I do this?