lundi 30 mai 2016

Loop gets stuck on 1st iteration

While trying to create a web crawler, I'm trying to define this function:

#a and b are lists.
def union(a, b):
    i = 0
    for e in b:
        if b[i] not in a :
            a = a.append(b[i])   
        i = i + 1    
    return a

then testing it, I input:

a = [1,2,3]
b = [2,4,6,9]
union(a,b)

It keeps giving me the error

TypeError: argument of type 'NoneType' is not iterable

I've seen a solution for this problem in another thread by editing my condition to if a and b[i] not in a:, but while testing, that only solves it until I append 1 element of b to a, then stops working.

Aucun commentaire:

Enregistrer un commentaire