mercredi 27 juillet 2016

Get unique values from a list in python

I want to get the unique values from the following list:

[u'nowplaying', u'PBS', u'PBS', u'nowplaying', u'job', u'debate', u'thenandnow']

The output which I require is:

[u'nowplaying', u'PBS', u'job', u'debate', u'thenandnow']

I tried the following code:

for x in trends:
    if x not in output:
        output.append(x)
        print output

but it didn't work. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire