Use the itertools.groupby()
function to group these:
from itertools import groupby
from operator import itemgetter
for value, group in groupby(list_of_dicts, key=itemgetter('value')):
print 'Group for value {}'.format(value)
for d in group:
print d
Demo:
>>> from itertools import groupby
>>> from operator import itemgetter
>>> list_of_dicts = [{'timestamp': u'1389631816', 'value': u'0'},
... {'timestamp': u'1389633136', 'value': u'0'},
... {'timestamp': u'1389633256', 'value': u'1'},
... {'timestamp': u'1389633316', 'value': u'1'},
... {'timestamp': u'1389633196', 'value': u'0'},
... {'timestamp': u'1389633196', 'value': u'0'},
... {'timestamp': u'1389633196', 'value': u'0'},
... {'timestamp': u'1389633316', 'value': u'1'}]
>>> for value, group in groupby(list_of_dicts, key=itemgetter('value')):
... print 'Group for value {}'.format(value)
... for d in group:
... print d
...
Group for value 0
{'timestamp': u'1389631816', 'value': u'0'}
{'timestamp': u'1389633136', 'value': u'0'}
Group for value 1
{'timestamp': u'1389633256', 'value': u'1'}
{'timestamp': u'1389633316', 'value': u'1'}
Group for value 0
{'timestamp': u'1389633196', 'value': u'0'}
{'timestamp': u'1389633196', 'value': u'0'}
{'timestamp': u'1389633196', 'value': u'0'}
Group for value 1
{'timestamp': u'1389633316', 'value': u'1'}