I am trying the run-length encoding problem, and after running a groupby & list operation, my groupby object somehow disappeared.
import itertools
s = 'AAAABBBCCDAA'
for c, group in itertools.groupby(s):
print(list(group))
print(list(group))
My output is
['A', 'A', 'A', 'A']
[]
['B', 'B', 'B']
[]
['C', 'C']
[]
['D']
[]
['A', 'A']
[]
so for each loop, the 2 print commands yield different results.
Can anybody help to explain what I did wrong?