Given a list:
mylist = [\'dog\', \'cat\', \'mouse_bear\', \'lion_tiger_rabbit\', \'ant\']
I\'d like a one-liner to return a new list:
using the itertools recipe to flatten a list you could do this:
from itertools import chain
mylist = ['dog', 'cat', 'mouse_bear', 'lion_tiger_rabbit', 'ant']
new_list = list(chain.from_iterable(item.split('_') for item in mylist))
print(new_list)
# ['dog', 'cat', 'mouse', 'bear', 'lion', 'tiger', 'rabbit', 'ant']
...or does the import statement violate your one-liner requirement?