Quantcast
Channel: How can I partition (split up, divide) a list based on a condition? - Stack Overflow
Viewing all articles
Browse latest Browse all 41

Answer by kiran for How can I partition (split up, divide) a list based on a condition?

$
0
0

Not sure if this is a good approach but it can be done in this way as well

IMAGE_TYPES = ('.jpg','.jpeg','.gif','.bmp','.png')files = [ ('file1.jpg', 33L, '.jpg'), ('file2.avi', 999L, '.avi')]images, anims = reduce(lambda (i, a), f: (i + [f], a) if f[2] in IMAGE_TYPES else (i, a + [f]), files, ([], []))

Viewing all articles
Browse latest Browse all 41

Trending Articles