Ad
  • Custom User Avatar

    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]
    

    Hope i did it good.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution