|
4 | 4 | import numpy as np
|
5 | 5 |
|
6 | 6 |
|
7 |
| - |
8 |
| - |
9 | 7 | def commonElement(list1, list2, option='dext'):
|
10 | 8 | '''
|
11 | 9 | function to identify common element in the list
|
12 | 10 | option: 'dext' enables to look at the basefilename without the extension useful to check if the files
|
13 | 11 | were in deed compressed
|
14 | 12 | '''
|
| 13 | + if len(list1)<len(list2): |
| 14 | + tmp = list1 |
| 15 | + list1 = list2 |
| 16 | + list2 = list1 |
| 17 | + |
| 18 | + list1Name = os.path.dirname(list1[0]) |
| 19 | + list2Name = os.path.dirname(list2[0]) |
| 20 | + |
15 | 21 | if option == 'dext':
|
16 |
| - list1 = [x.split(os.sep)[-1].split('.')[0] for x in list1] |
17 |
| - list2 = [x.split(os.sep)[-1].split('.')[0] for x in list1] |
| 22 | + # modification takes care of multi period in the path |
| 23 | + list1 = [('.').join(x.split(os.sep)[-1].split('.')[:-1]) for x in list1] |
| 24 | + list2 = [('.').join(x.split(os.sep)[-1].split('.')[:-1]) for x in list2] |
| 25 | + # list1 = [x.split(os.sep)[-1].split('.')[0] for x in list1] |
| 26 | + # list2 = [x.split(os.sep)[-1].split('.')[0] for x in list2] |
18 | 27 |
|
19 | 28 | commonElem = [x for x in list1 if x in list2]
|
20 | 29 |
|
21 | 30 | print('There are', len(commonElem), 'out of', max(len(list1), len(list2)), 'files which are common')
|
| 31 | + print('For', list1Name, ':') |
| 32 | + print(len(commonElem), 'out of', len(list1), 'files which are common') |
| 33 | + print('For', list2Name, ':') |
| 34 | + print(len(commonElem), 'out of', len(list2), 'files which are common') |
| 35 | + |
| 36 | + notcommonElem = [x for x in list2 if x not in list1] |
| 37 | + # alternatively could use np.setdiff1d(list1, list2) |
| 38 | + print('None common elements present in', list2Name, ' : ') |
| 39 | + print(notcommonElem) |
| 40 | + |
| 41 | + |
| 42 | + ## toDel = [os.remove(''.join([list2Name,os.sep,x,'.avi'])) for x in commonElem] |
| 43 | + |
| 44 | + |
| 45 | + # return notcommonElem |
22 | 46 |
|
23 |
| - notcommonElem = [] |
24 |
| - if max(len(list1), len(list2)) != len(commonElem): |
25 |
| - notcommonElem = [x for x in list1 if x not in list2] |
26 |
| - # alternatively could use np.setdiff1d(list1, list2) |
27 |
| - print('None common element are:') |
28 |
| - print(notcommonElem) |
29 |
| - else: |
30 |
| - print('No none common element found') |
31 | 47 |
|
32 |
| - return notcommonElem |
33 | 48 |
|
34 | 49 |
|
35 | 50 | def getSize(filesList):
|
|
0 commit comments