[Solved] How to get all seperate all equal pairs from a list in python


print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b]

you may need to sort my_list first …

my_list = sorted(my_list)
print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b]

Im not at all sure this solves your issue.

def do_this_weird_thing(a_list):
    from itertools import groupby
    for grp,item in groupby(sorted(a_list)):
        item = list(item)
        yield [grp] * (len(item)//2)

from itertools import chain
print list(chain.from_iterable(do_this_weird_thing([2,0,2,4])))

0

solved How to get all seperate all equal pairs from a list in python