groupby() take iterable(sort of sequence) and return tuple of group key(str) and lazy iterator(itertols._grouper).
So because its lazy it will give you a value only as in needed. But you can get sum of iterators values.
for k,g in groupby(s):
print(type(k)) # str
print(type(g)) # itertols._grouper
x = sum(1 for _ in g)
print(f'This is a key {k} and these is a sum {x} of the each group'}
Then you need to create generator expression, which consist of
[[computing_sum_of_the_group=example above, key] for key, group in each_tuple]
groupby()
take iterable(sort of sequence) and return tuple of group key(str) and lazy iterator(itertols._grouper).So because its lazy it will give you a value only as in needed. But you can get sum of iterators values.
Then you need to create generator expression, which consist of
Hope i did it good.
thanks for explaining!
Can you please explain this solution? thanks
Can anyone explain this solution? thanks