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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

java - How to implement an entity bound odata action in olingo v4.3 -