Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14126

Python using endswith method issue with remove from list [duplicate]

$
0
0

This is my code:

domains = ['google.com', 'yahoo.co', 'bing.msn', 'biz.info', 'you.biz', 'test.store', 'myblog.blog', 'finally.xyz']extensions = ['.blog', '.co', '.com', '.store', '.xyz']

Finally, I'm going to remove domain names which have the extension in the extensions list, and keep other domains which do not have those extensions.

Expected output is:

domains = ['bing.msn', 'biz.info', 'you.biz']

I tried this too (former edit3):

>>> domains[:] = [x for x in domains for e in extensions if not x.endswith(e)]>>> domains['google.com', 'google.com', 'google.com', 'google.com', 'yahoo.co', 'yahoo.co', 'yahoo.co', 'yahoo.co', 'bing.msn', 'bing.msn', 'bing.msn', 'bing.msn', 'bing.msn', 'biz.info', 'biz.info', 'biz.info', 'biz.info', 'biz.info', 'you.biz', 'you.biz', 'you.biz', 'you.biz', 'you.biz', 'test.store', 'test.store', 'test.store', 'test.store', 'myblog.blog', 'myblog.blog', 'myblog.blog', 'myblog.blog', 'finally.xyz', 'finally.xyz', 'finally.xyz', 'finally.xyz']

Viewing all articles
Browse latest Browse all 14126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>