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 Shay for How can I partition (split up, divide) a list based on a condition?

$
0
0

Yet another answer, short but "evil" (for list-comprehension side effects).

digits = list(range(10))odd = [x.pop(i) for i, x in enumerate(digits) if x % 2]>>> odd[1, 3, 5, 7, 9]>>> digits[0, 2, 4, 6, 8]

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>