|
|
|
|
|
by kamray23
1835 days ago
|
|
Yeah, I'd much rather have something like congruence_classes m l = map (\x -> ((x ==) . (`mod` m)) l) [0..m-1]
than def congruence_classes(m, l):
sets = []
for i in range(m):
sets += [[]]
for v in l:
sets[v % m] += [v]
return sets
For-in is very neat and nice but it still takes two loops and mutation to get there. Simple things are sometimes better as one-line maps. Provability is higher on functional maps too.Same one-liner in (slightly uglier) Python: def congruent_sets(m, l):
return list(map(lambda x: list(filter(lambda v: v % m == x, l)), range(m)))
|
|
Ironically, it's a great example of why readability is so much more important than conciseness and one liners.