I have actual filenames and expected filenames lists. I have to file matched elements of two list and write it in one row of csv file. And the rest of elements that unmatched in expected filenames lists has to be written in any place of elements of actual filename

I have written code to like if actual filename in expected filenames write in the same row of csv file, else blank. But i need every rest of unmatched elements of expected files to be written in any row of actual filename. If expected filename ends, please leave blank.

Expected filenames

['AGN_2014Q4', 'AGN_2015Q4', 'AGN_2016Q4', 'AGN_2017Q4', 'AGN_2018Q4', 'AGN_2014Q3', 'AGN_2015Q3', 'AGN_2016Q3', 'AGN_2017Q3', 'AGN_2018Q3', 'AGN_2014Q2', 'AGN_2015Q2', 'AGN_2016Q2', 'AGN_2017Q2', 'AGN_2018Q2', 'AGN_2014Q1', 'AGN_2015Q1', 'AGN_2016Q1', 'AGN_2017Q1', 'AGN_2018Q1']

Actual filenames

['AGN_2016Q1', 'AGN_38', 'AGN_2014Q3', 'AGN_19', 'AGN_2017Q4', 'AGN_2018Q4', 'AGN_31', 'AGN_2018Q1','AGN_2015Q1', 'AGN_2016Q4', 'AGN_2017Q2', 'AGN_2017Q3', 'AGN_2016Q2', 'AGN_2015Q4', 'AGN_2018Q2', 'AGN_2015Q3', 'AGN_2017Q1', 'AGN_2018Q3', 'AGN_35', 'AGN_2015Q2', 'AGN_34', 'AGN_2016Q3']

Result should be in csv file 2 column (https://docs.google.com/spreadsheets/d/1CjMgIqc7BXrYx91AxGI7AIxsgcjW1fB4QRlnTHF9OGw/edit?usp=sharing)

1 Answers

A. Albershteyn On Best Solutions

Two list with same and different values:

>>> a = ['a', 'b', 'c', 'd']
>>> b = ['c', 'd', 'e', 'f'] 

First, same values in both lists:

>>> list(set(a).intersection(b))
['c', 'd']

Now, unique in first and unique in second list:

>>> list(set(a) - set(b))
['b', 'a']
>>> list(set(b) - set(a))
['e', 'f']

However, as you can see it loses order. You can sort list with a.sort()