I have a list that I need to extract, via 'filter', certain matching values. The problem is that the 'append' method seems to create an array while appending the matching values. How do I change this behavior?
My code:
v_Files = ['aaa.mp3', 'hhh.mp4', 'jjj.txt', 'uuu.xls', 'ujh.mp3', 'hun.m4p']
print("Files list: %s") %(v_Files)
v_NewFiles = (filter(lambda element: 'mp3' in element, v_Files))
v_NewFiles.append(filter(lambda element: 'mp4' in element, v_Files))
v_NewFiles.append(filter(lambda element: 'm4p' in element, v_Files))
print("New files list: %s") %(v_NewFiles)
And the output:
Files list: ['aaa.mp3', 'hhh.mp4', 'jjj.txt', 'uuu.xls', 'ujh.mp3', 'hun.m4p']
New files list: ['aaa.mp3', 'ujh.mp3', ['hhh.mp4'], ['hun.m4p']]
As can be seen, the new list from the 'append' method has become a mess.
Feedback would be appreciated. Thanks.