Aug-01-2019, 06:39 PM
(Aug-01-2019, 11:32 AM)Friend Wrote: i don't know why this shouldn't work, what exactly didn't work by using 'startswith':
if filename.startswith('...') # your five lettersYeah, an example would help understanding what you really need
My directory and file structure is as below
Main_Folder
--SubFolder1
---aaa_001
---bbb_002
--SunFolder2
---aaa_002
---bbb__004
So the idea is I want to group files based on the first 3 characters in this case and have a dictionary structure that will look as below when printing the file_list
{aaa: [aaa_001,aaa_002],
bbb: [bbb_002, bbb_004]}
when using startswith it just gives a true or false value but the result i get is as below:
{aaa_001: [aaa_001],
aaa_002: [aaa_002],
bbb_002: [bbb_002],
bbb_004:[bbb_004]}