user3866022
user3866022

Reputation: 1

Nested for loop not working?

def remove_duplicates (user_input):
    black_list = []
    new_list = []
    for i in user_input:
        for t in black_list:
            if i == t:
                break
            else:
                new_list.append(i)
                black_list.append(i)
    return new_list

I've been taking classes from codecademy and I tried to tackle a problem this way but the second loop doesn't seem to be executing and I've check via print statements throughout the loops but I can't seem to get it to work.

Upvotes: 0

Views: 24

Answers (1)

bjornruffians
bjornruffians

Reputation: 701

black_list is declared empty, []. Therefore the 2nd for-loop will execute 0 iterations.

Upvotes: 2

Related Questions