PS
BAN USERHere's a Python Solution :
#Input stored in a Dictionary
dict = {'Nick Fury':['Tony Stark','Maria Hill','Norman Osborn'],
'Hulk':['Tony Stark','HawkEye','Rogers'],
'Rogers':['Thor'],
'Tony Stark':['Pepper Pots','Nick Fury'],
'Agent 13' : ['Agent-X', 'Nick Fury', 'Hitler'],
'Thor': ['HawkEye', 'BlackWidow'],
'BlackWidow':['HawkEye'],
'Maria Hill' : ['Hulk', 'Rogers', 'Nick Fury'],
'Agent-X' : ['Agent 13', 'Rogers'],
'Norman Osborn': ['Tony Stark', 'Thor']
}
def main():
tup = []
list_dict = []
flag = 0
'''creating an array of tuples for all the SHIELD members.
Every tuple has two elements : (SHIELD member name, Flag)
***Flag is set to 1 when the member name is visited i.e. becomes the key
in the dictionary such that its values are accessed'''
tup.append(('Nick Fury',1))
for el in dict['Nick Fury']:
tup.append((el,0))
for k,v in enumerate(tup):
if tup[k][1] == 0:
temp = list(tup[k])
temp[1] = 1
tup[k] = tuple(temp)
if tup[k][0] in dict.keys():
for el in dict[tup[k][0]]:
flag = 0
for item in tup:
if item[0] == el:
flag = 1
break
if flag == 0:
tup.append((el,0))
#Creating a list list_dict of all the unique SHIELD member names from the dictionary
for key in dict.keys():
for val in dict[key]:
if val not in list_dict:
list_dict.append(val)
#Extracting only names from the list of tuples into the list tup_names
tup_names, flag = zip(*tup)
tup_names = list(tup_names)
#Comparing the two lists and removing common names
for person in tup_names:
list_dict.remove(person)
print 'HYDRA MEMBERS:'
print list_dict
if __name__ == "__main__":
main()
Code in Python:
- PS September 09, 2017