I'm trying to use Python 3 to use list_one to sort list_two and output to list_sorted. If the value of a field is missing then I'd like to see a null value placed. The output would have the same number of items as list_one
list_one = ['one', 'two', 'three', 'four', 'five', 'six', 'seven']
list_two = ['seven', 'five', 'four', 'three', 'one']
list_sorted = []
for i in list_one:
for field in list_two:
if i == field:
list_sorted.append(field)
else:
list_sorted.append(None)
print ('final output:', list_sorted)
The desired output is:
['one', None, 'three', 'four', 'five', None, 'seven']
But it's actually outputting:
[None, None, None, None, 'one', None, None, None, None, None, None, None, None, 'three', None, None, None, 'four', None, None, None, 'five', None, None, None, None, None, None, None, None, 'seven', None, None, None, None]
My current thinking is the answer involves enumerate but I'm not sure. Any help would be greatly appreciated.