I am having a hard time to solve the following issue: I have to merge N lists. Each list contains some string objects. For each list, although I do not know which is the ordering function, I know that it is ordered. Moreover, the final list should respect all the ordering of the child that generated it. For instance:
l1 = ['This','world']
l2 = ['This','is','a','world','!']
l3 = ['a','hello','world']
merged_list = merge_function(l1,l2,l3)
The results I would like to achieve is to receive a list containing
merged_list # ['This','is','a','hello','world','!']
But I cannot figure out the way to do it, as the lists are not following any rule beside the order in which the elements are provided. Any help would be appreciated.
EDIT: The focus of my question is not on how to merge some lists. The problem is that the elements should be merged in a way that they respect all the ordering of the original lists. So I cannot use sets as they have their own ordering policy. I think I have to stick to lists because they are more flexible, but I need to find a way to insert new elements in the correct position within the final list, as I cannot simply append them.
For instance:
l1 = ['This','world']
l2 = ['This','is','a','world','!']
merged_list = l1
If I then simply append the missing element to the merged_list I would obtain:
merged_list # ['This','world','is','a','!']
and this list breaks the ordering of l2. I hope now I explained the issue a bit better.