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

$
0
0

If you insist on clever, you could take Winden's solution and just a bit spurious cleverness:

def splay(l, f, d=None):  d = d or {}  for x in l: d.setdefault(f(x), []).append(x)  return d

Viewing all articles
Browse latest Browse all 41

Trending Articles



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