Given two lists of strings that contain duplicates save for one element in each list, how would you combine the two into a single list that contains one copy of every value in list order?
For example, given the following two lists in Python:
a = ['Second', 'Third', 'Fourth']
b = ['First', 'Second', 'Third']
Or
a = ['First', 'Third', 'Fourth']
b = ['First', 'Second', 'Third']
How would you combine the two lists to get a single list like this:
result = ['First', 'Second', 'Third', 'Fourth']
Note that the exact values of the strings cannot necessarily be trusted to help with ordering the elements.
I am aware of the possibility that there will be some cases with no definitive way to lock the list down to a particular order, and will probably have to special-case those, but for the general cases I'd rather have a procedure to follow. For example:
a = ['First', 'Third', 'Fourth']
b = ['First', 'Second', 'Fourth']
This could have 'Third' and 'Second' in either order, as there's no item on both lists between them to provide a guideline.
Edit: I should explain the strings a bit further, as I see many of you are assuming that I can merely sort a raw merge of the two lists, and this just isn't going to work.
I'm taking story titles, which, for each story, only list the other instalments and not the linked story itself. So by taking two lists (or possibly more, I'm not sure), I can come up with a full list of the instalments to put them in their proper order.
['First', 'Second', 'Fourth']and['First', 'Third', 'Fourth']? Without knowing the correct order by some other means, there is no way the program can tell whether'Second'or'Third'comes first.