4 ms·
I'll visit that channel when back from vacation for sure. To do what you want you could use list comprehensions or the filter(function, sequence) function: Li
by buster 15y ago
I'll visit that channel when back from vacation for sure.
To do what you want you could use list comprehensions or the filter(function, sequence) function:
List comprehension:
links = ["https://securesite.com", "http://unsecuresite.com", "https://sec2.com", "http://unsec2.com"]
[url for url in links if not url.startswith("https")]
>>> ['http://unsecuresite.com', 'http://unsec2.com']
filter() + lambda:
links = ["https://securesite.com", "http://unsecuresite.com", "https://sec2.com", "http://unsec2.com"]
filter(lambda url: not url.startswith("https"), links)
['http://unsecuresite.com', 'http://unsec2.com']
I'd go with the list comprehension, from your use of map i'd guess you'd go with the filter ;)
Of course you'd replace the url.startswith with whatever your criteria is.
- Mithaldu 15y agoAh, that's kinda what i expected. Suddenly the two languages look fairly similar, no? :) Also, list comprehension doesn't look bad to me. It's just a slightly weird and more verbose syntax of doing map, while filter does an in-place operation.