jeudi 27 mai 2021

In python, why doesn't this string append with a for loop work?

I want to make a for loop that checks if list d has elements from list ident and if they don't, I want to add them. When I run this code part by part it works, but I suspect my False statement is not working, because it just doesn't append.

import pandas as pd
ident=['bla','me','you']
d=['bla']
for x in range(len(ident)):
    if ident[x] in d == False:
        d.append(ident[x])

Here is how I want the output to be:

d=['bla','me','you']

Aucun commentaire:

Enregistrer un commentaire