I made a function which filters my list and it looks like
def listDirs(directory): listD = [d for d in [os.path.join(myPath, d1) for d1 in os.listdir(directory)] if os.path.isdir(d)] sortListD = np.unique(np.array([i[-10:] for i in listD])) if[ np.array([i.split("-")[1] for i in sortListD]) != "2017" ]: # <- here sortListD.remove(i) return sortListD As you imagine, the line marked does not work and I'm not really comfortable with the usage of python loops.
What i want to do is to verify that my i element in my sortListD is formatted as 'YYYY-MM-DD', and remove it if not.
my sortListD looks like this:
['2015-06-18' '2015-07-20' '2015-08-05' '2015-09-01' '2015-10-10' '2016-01-04' '2016-01-06' '2016-01-11' '2016-01-18' '2016-01-20' '2016-02-15' '2016-02-25' '2016-04-16' '2016-05-03' '2016-06-07' '2016-06-21' '2016-06-22' '2016-06-24' '2016-07-30' '2016-08-02' '2016-08-23' '2016-09-07' '2016-09-15' '2016-09-19' '2016-09-28' '2016-09-30' '2016-10-03' '2016-10-06' '2016-10-10' '2016-10-17' '2016-11-07' '2016-11-11' '2016-11-14' '2016-11-18' '2016-11-23' '2016-11-27' '2016-12-08' '2016-12-12' '2016-12-20' '2017-01-03' '2017-01-06' '2017-02-02' '2017-02-03' '2017-02-20' '2017-04-20' '2017-05-08' '2017-05-22' '2017-06-01' '2017-09-23' '2017-11-16' '2017-11-23' '2017-11-30' '**ata_Q1/old**' '**uonic_data**'] The elements in bold are the one i want to remove.