I know this question has been discussed before, and I know this is such a novice and easy question, but for some reason I can’t wrap my head around the code that would be needed to do this. Here is a practical example that I need this for:
Lets say I contain a tumblr account, and I follow 5 people, of which 3 follow me back.
iFollow = [Tom, Richard, Bob, Samantha, Kat]
followsMe = [Samantha, Kat, Bob]
Now, I want to unfollow the people that I follow, however don’t follow me back.
So in this example I would want to unfollow Tom and Richard, because even though I follow them, they don’t follow me. I would like to create a list:
unfollowThese = [Tom, Richard]
I can’t for the life of me figure out how to do this. I know there is intersect, find the common elements, that would output “Bob”, it seems like I want the opposite, I want elements that are common in both lists removed from the new list that I want to make.
I.E. I want elements common in iFollow and followsMe to be removed from unfollowThese, as I don’t want to unfollow my followers.
Thanks.
p.s. if you can think of a better title, please change it, I couldn’t think of anything to call it..
Using list comprehensions if order matters:
Using
setsif the order of items does not matter: