def who_knows(a, b):
""" a and b are lists """
c = [] # create empty list "c"
for i in a: # loop over items in the a list, "i" represents each item
if is_mem(b, i): # calls is_mem() for each item, checks if the item exists in the b list
c.append(i) # if it does, append it to the c list
return uniqify(c) # call function uniqify() with the new c list
def is_mem(a, elem):
for i in a: # for each item in the list
if i == elem: # if the input argument "elem" exists in the list
return True # ...return True
return False # otherwise return False
def uniqify(arr):
b = {} # create dictionary (key/value mapping)
for i in arr: # for each item "i" in the input list "arr"
b[i] = 1 # set b[i] = 1, duplicates overwites existing value
return b.keys() # return all distinct items
|