I have a list question using the following script:
list1=['a','b','c','d','e','f']
list2=['1A','1B','1C','1a','1b','1c']
list3=[]
list4=[]
for i in list1:
for j in list2:
if i in j: list3.append(j)
for i in list1:
if i not in list3: list4.append(i)
List3 correctly contains:
1a
1b
1c
But list4 contains:
a
b
c
d
e
f
However, if I use ‘if i not in str(list3): list4.append(i)’ list4 correctly lists:
d
e
f
There’s apparently something basic in lists I don’t understand. The numeral 1 seems to cause the original code to fail. For if I delete the 1’s from list2, list4 displays correctly using the original code and not str(list3).
I understand 1 is an integer, but the elements in list2 are strings. ?
list1=['a','b','c','d','e','f']
list2=['1A','1B','1C','1a','1b','1c']
list3=[]
list4=[]
for i in list1:
for j in list2:
if i in j: list3.append(j)
for i in list1:
if i not in list3: list4.append(i)
List3 correctly contains:
1a
1b
1c
But list4 contains:
a
b
c
d
e
f
However, if I use ‘if i not in str(list3): list4.append(i)’ list4 correctly lists:
d
e
f
There’s apparently something basic in lists I don’t understand. The numeral 1 seems to cause the original code to fail. For if I delete the 1’s from list2, list4 displays correctly using the original code and not str(list3).
I understand 1 is an integer, but the elements in list2 are strings. ?