Example 2
suggest changeThis 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents