Python - identify items from list where sublist items are duplicated -


awful title, please rename or generalise appropriate.

scenario:

inputlist = [[1, "data x"], [2, "data z"], [3, "data x"]] 

i want find there duplicates of index[1].

desiredoutput = [[1, "data x"], [3, "data x"]] 

ideally, [1] list, instead of string:

[[1, ["data x1", "data x2"], [2,  ["data x1", "data x2"]] 

how (just alternative)

inputlist = [[1, "data x"], [2, "data z"], [3, "data x"]]  operator import itemgetter collections import defaultdict  dd = defaultdict(list) i, v in enumerate(inputlist):     dd[v[1]].append(i)  dupes = [itemgetter(*v)(inputlist) v in dd.itervalues() if len(v) > 1] # [([1, 'data x'], [3, 'data x'])] 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -