I am trying to figure out if it is possible to make a list comprehension if you create more than one element of the target list in one step.
Lets have a list like this: input_list=['A','B','C/D','E']
and what I want to get in the end is output_list=['A','B','C','D','E']
.
This is the piece of code I have now:
output=[]
for x in input:
if '/' in x:
output+=x.split('/')
else:
output.append(x)
The only list comprehension that I came up with was: [x.split('/') if '/' in x else x for x in input]
but obviously, it is not what I need as it outputs this nested list: ['A','B',['C','D'],'E']
Is it possible, or I just want too much from a simple list comprehension?