Tuesday, 13 August 2013

Python - identify items from list where sublist items are duplicated

Python - identify items from list where sublist items are duplicated

Awful title, please rename or generalise as appropriate.
Scenario:
inputList = [[1, "Data x"], [2, "Data z"], [3, "Data x"]]
I want to find where there are duplicates of index[1].
DesiredOutput = [[1, "Data x"], [3, "Data x"]]
Ideally, the [1] would be another list, instead of a string:
[[1, ["Data x1", "Data x2"], [2, ["Data x1", "Data x2"]]

No comments:

Post a Comment