I have following code from which I expect the output as : ['abcdef'] ['def']. I want the a2 list to contain unique elements of a1 that are not present in variable x.
>>> a1=[]
>>> a2=[]
>>> a1.append("abcdef")
>>> x="abc"
>>> if x not in a1:
... a2.append(a1)
...
>>> print a1, a2
['abcdef'] [['abcdef']]
Any help is appreciated.
- This question is NOT a duplicate of Appending an id to a list if not already present . My question deals with appending a substring.