I have a list of lists which I want to flatten while inserting an item in between them. My original list is in the form:
l = [["a","b"],["c"],["d"]]
What I want is, to flatten the list and separate them with a character
n = ["a","b",".","c",".","d"]
Flattening lists should be possible on with list comprehension as mentioned in many SO answers:
flat_list = [item for sublist in l for item in sublist]
but is it possible to flatten the list with a character/string of my choosing?
It could be done with by appending .
to each list except the last one. But is there something more elegant like .join
?