Quantcast
Viewing all articles
Browse latest Browse all 41

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

images = [f for f in files if f[2].lower() in IMAGE_TYPES]anims  = [f for f in files if f not in images]

Nice when the condition is longer, such as in your example. The reader doesn't have to figure out the negative condition and whether it captures all other cases.


Viewing all articles
Browse latest Browse all 41

Trending Articles