Looking for some pointers on where to start with this as I’m at a bit of a loss.
I have a variable number of lists with a variable number of items in each. In these lists some elements repeat sequentially that I would like to ‘Group’. For instance, the list B, A, B, C, C, C, A, C, A, A would become B, A, B, 3C, A, C, 2A.
Ideally, I’d like to do it with nodes as my Python journey has stalled yet again but even a starting point would be great!
No, unfortunately not… this might explain it better, I essentially need to count the number of consecutive items in a list… when the item value changes the count restarts. Does that make sense?
from itertools import groupby
grouped = [(len(list(groups)),keyValue) for keyValue,groups in groupby(IN[0])]
OUT = [str(count)+str(key) if count>1 else str(key) for count,key in grouped]
Thanks for taking the time to look at this but unfortunately what you have doesn’t quite work for me as it’s just totaling the different unique values - I need to preserve the original list format and just group values where they duplicate. @AmolShah solution hits the mark though so all good from my end.