Example 2

suggest change

This example illustrates the default key if we do not specify one. groupby is not imported in this snippet. With no key, each element is its own group key.

c = groupby(['goat', 'dog', 'cow', 1, 1, 2, 3, 11, 10, ('persons', 'man', 'woman')])
dic = {}
for k, v in c:
    dic[k] = list(v)
dic

Results in

{'goat': ['goat'], 'dog': ['dog'], 'cow': ['cow'], 1: [1, 1], 2: [2], 3: [3], 11: [11], 10: [10], ('persons', 'man', 'woman'): [('persons', 'man', 'woman')]}

Notice here that the tuple as a whole counts as one key in this list

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents