I have this list:
[('airplane', 'ship'),
('car', 'truck'),
('bird', 'dog'),
('cat', 'horse'),
('cat', 'monkey'),
('dog', 'cat'),
('dog', 'deer'),
('horse', 'dog'),
('horse', 'monkey'),
('deer', 'cat'),
('deer', 'horse'),
('monkey', 'bird'),
('monkey', 'dog'),
('monkey', 'deer')]
I want to group these words as following:
1- Each pair words have the same group like; ('airplane', 'ship') -> airplane and ship in the same group ('car', 'truck'),-> 'car' and 'truck'in the same group
2-In the 2 pairs ('cat', 'horse'), ('cat', 'monkey'), i want to put "cat" and 'horse'and 'monkey' in the same group
3-Also In the 3 pairs ('monkey', 'bird'),('monkey', 'dog'), ('monkey', 'deer') i want to put 'monkey' and 'bird' and 'dog'and 'deer'in the same group
in the output i want to find this results:
[['airplane', 'ship'],['car', 'truck'],[ 'monkey' ,'bird','dog','deer','cat','horse']]