Tutorial by Examples

Say you have the string s = 'AAAABBBCCDAABBB' and you would like to split it so all the 'A's are in one list and so with all the 'B's and 'C', etc. You could do something like this s = 'AAAABBBCCDAABBB' s_dict = {} for i in s: if i not in s_dict.keys(): s_dict[i] = [i] els...
This example illustrates how the default key is chosen if we do not specify any 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 {1: [1, 1], 2: [2], 3: [3], ('persons', 'man', 'woman'): [('...
Notice in this example that mulato and camel don't show up in our result. Only the last element with the specified key shows up. The last result for c actually wipes out two previous results. But watch the new version where I have the data sorted first on same key. list_things = ['goat', 'dog', 'do...
In this example we see what happens when we use different types of iterable. things = [("animal", "bear"), ("animal", "duck"), ("plant", "cactus"), ("vehicle", "harley"), \ ("vehicle", "speed b...

Page 1 of 1