So I have this list that contains lots of filenames in a directory with its respective types. Say that the list look like this:
list = ['apple-20220103.csv', 'apple_tea-20220304.csv', '20220203-apple_town.csv', 'apple_town20220101.csv']
and the types of file are stored in a .csv file like this:
,type
0,apple
1,apple_tea
2,apple_town
I want to classify each filename in the list into its respective type of file and put them into a dictionary. Say that the dictionary would look like this after processed:
dictionary = {
'apple':['apple-20220103.csv'],
'apple_tea':['apple_tea-20220304.csv'],
'apple_town':['20220203-apple_town.csv', 'apple_town20220101.csv'
}
The question is how can I ensure so that apple would not receive any file besides apple-20220103.csv, despite other filenames also contain the word apple in it? I've tried using simple regex matching, and the result still has apple_tea and apple_town filenames in apple.