This problem feels basic and I must be overlooking something obvious. There are many posts on Stack related to this but nothing I have found quite covers this use case.
I have two lists - One with URLs and one with substrings:
list1 = ['https://', 'http://', 'woof://', 'meow://']
list2 = ['https://google.com', 'stackoverflow.com', 'meow://test.net', 'yahoo.com']
I want to create a third list where all the values from list1
are removed from list2.
For example - list3 = ['google.com', 'stackoverflow.com', 'test.net', 'yahoo.com']
I have tried:
for x in list1:
for y in list2:
if x in y:
list3.append(y.replace(x, '')
else:
list3.append(y)
This creates a list with a lot of duplicates. I could probably add logic to clean list3
up but I feel as though there must be a much more pythonic way to do this.
I feel like this post is close to what I am looking for but not quite there.