mardi 14 février 2017

How do i append another list within list comprehension

Vote count: 0

I am trying to find out unique elements and avoid duplicates , between the lists (using list comprehension)

`a = [10 , 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,9]`
`b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]`

dup_list = []

This works , but with duplicates

`final_list = [uniq for uniq in a if a not in dup_list if uniq in b ]`

when i try to append the my dup_list in the last line of the comprehension statement it says invalid syntax i.e this doesn't work. "final_list = [uniq for uniq in a if a not in dup_list if uniq in b dup_list.append(uniq) " I am a newbie in python so apologize for any missed out basic facts .

asked 6 secs ago

Let's block ads! (Why?)



How do i append another list within list comprehension

Aucun commentaire:

Enregistrer un commentaire