Lets say I have a list x:
x=['alfa[1]', 'bravo', ('charlie[7]', 'delta[2]'), 'echo[3]']
I want to create a new list which both flattens and removes the bracketed number if the item has one. The result should be:
x_flattened_bases = ['alfa', 'bravo', 'charlie', 'delta', 'echo']
Here is what I currently have:
x_flattened_bases = []
for item in x:
if isinstance(item, tuple):
x_flattened_bases.extend([value.split('[')[0] for value in item)
else:
x_flattened_bases.append(item.split('[')[0])
There is only 1 level of nesting in the list.