如何实现两个有相似元素列表,其中一个删除相似元素——python
#Before the starting
This is my first blog, cause i want to learn english, so i will try to finish every blog all by english. i hope my english will turn to be great!!!
#the following is the main body
here have two lists,
str1 = [1,2,3,4]
str2 = [3,4,5,6]
i want to find the elements that is in str1 but not in str2, at the first, i try the following code:
// An highlighted block
for i in str1:
if i in str2:
str1.remove(i)
print(str1)
I hope the result was ‘[1,2]’,however the result is ‘[1,2,3]’. this confused me, and i take so much time to figure out whe