List of dict unique combination Python -


i have big data visualization purpose, example list of dict as,

input :

a = [{'e1': 'a','e2': 'b'}, {'e1': 'b','e2': 'a'}, {'e1': 'a','e2': 'c'} ] 

output :

a = [{'e1': 'a','e2': 'b'}, {'e1': 'a','e2': 'c'}] 

detail: if {'e1': 'a','e2': 'b'} , {'e1': 'b','e2': 'a'} pointing each others value want unique {'e1': 'a','e2': 'b'}.

so e1 source , e2 target. if connection exists between source , target should unique. here connected b should not consider b connected a.

you may try 1

from itertools import groupby [j.next() , j in groupby(a, lambda x: sorted(x.values())) 

output:

[{'e1': 'a', 'e2': 'b'}, {'e1': 'a', 'e2': 'c'}] 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -