PyPK wrote:
> If I have a list say
>
> lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
> I want to group the list so that it returns groups such as
> [(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar.
>
> Thanks,
Hi,
I got a solution without iterators and without comparing adjecent
elemen
hmm thanks for that..but kind of not sure how this groupby works.. also
if I want to group elements with one value apart how would this
change.Should this change in groupby part or in the loop?
something like...
lst = [1,1,2,1,3,5,1,1,1,1,2,7,7]
returns (0,3),4,5,(6,10),(11,12)
so its something lik
I wasn't sure of what itertools.groupby() is good for. But it serves
your purpose.
>>> lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
>>>
>>> import itertools
>>> i = 0
>>> groups = []
>>> for k, g in itertools.groupby(lst):
... l = len(list(g))
... if l == 1:
... groups.append(i)
... else:
PyPK wrote:
> lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
> I want to group the list so that it returns groups such as
> [(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar.
You'll probably want to use "groupby" from the itertools module. See
http://docs.python.org/lib/itertools-functio
If I have a list say
lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
I want to group the list so that it returns groups such as
[(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar.
Thanks,
--
http://mail.python.org/mailman/listinfo/python-list