I'm trying to do something like that:
groups = groupby(all_data, key=itemgetter(1))
result = []
for k,g in groups:
gg = list(g)
count = len(gg)
v = gg[0][3:] #No empty groups, right?
hosts = ";".join([x[0] for x in gg])
result.append(v + (count,) + (hosts,))
I hate loops. ;) Is there any chance to do it with comprehension? The problem is g is iterator, not list and I have no idea how can I convert it to list in comprehension.
[list(g)[0][3:] + (len(list(g)),) + (';'.join(x[0] for x in list(g)[0][3:])) for k, g in itertools.groupby(all_data, itemgetter(1))]however it would be better if you provide your input and your expected output.