0

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.

Raw_Input
  • 341
  • 1
  • 5
  • 12
  • At least care to tag the language you are coding in. – Raj Jun 08 '14 at 02:54
  • I have just about abandoned tags, as just about all tags seem to require 1,500 rep. I will make sure to include Python in the future though. – Raw_Input Jun 08 '14 at 07:10

1 Answers1

0

I found the answer. Seems in my push to move beyond beginner I forgot some basic things. I found this. Seems I forgot about 'extend'.

Using 'extend' instead of 'append' solved my problem.

Community
  • 1
  • 1
Raw_Input
  • 341
  • 1
  • 5
  • 12