Y.G. Bae (23) [Avatar] Offline
#1
In the answer to Q25.3:

def common(L1, L2):
    L_unique_L1 = unique(L1)
    L_unique_L2 = unique(L2)
    return L_unique_L1 == L_unique_L2


though it's concise, it will return False on common([1,2,3], [3,1,2]) which is not what we want. Although we haven't learned just yet, sort() method can solve this problem, but if we have the elements with different types in the list, sort() method won't work.

There must be simpler ways, but my take on common function was like this:
def common(L1, L2):
    uniqueL1 = unique(L1)
    uniqueL2 = unique(L2)
    L1Length = len(uniqueL1)
    L2Length = len(uniqueL2)
    count1 = count2 = 0
    for item1 in uniqueL1:
        if item1 in L2:
            count1 += 1
    if count1 == L1Length:
        for item2 in uniqueL2:
            if item2 in L1:
                count2 += 1
        if count2 == L2Length:
            return True
    return False
Ana Bell (23) [Avatar] Offline
#2
Good catch. I rewrote it in this way:

def common(L1, L2):
    unique_L1 = unique(L1)
    unique_L2 = unique(L2)
    length_L1 = len(unique_L1)
    length_L2 = len(unique_L2)
    if length_L1 != length_L2:
        return False
    else:
        for i in range(length_L1):
            if L1[i] not in L2:
                return False
        return True
Y.G. Bae (23) [Avatar] Offline
#3
Excellent! Much simpler than mine! smilie Thank you. smilie