/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def partition(iterable, func): result = {} for i in iterable: result.setdefault(func(i), []).append(i) return result def group(seq): result = {} for item, category in seq: result.setdefault(category, []).append(item) return result # def is_odd(n): # return (n%2) == 1 # l = range(100) # print partition(l, is_odd) # print group( (item, is_odd(item)) for item in l) # print group( (item, item%11) for item in l) # no need to use lamda/def
Comments
