You can try something like this:
host = {
'abc.com': ['fruit_apple', 'fruit_orange', 'veg_carrots'],
'123.com': None,
'foo.com': ['fruit_tomatoes', 'veg_potatoes']
}
print({i:[k for k in j if not k.startswith('fruit_')] if j!=None else None for i,j in host.items() })
But if there is no None, you can try this interesting approach:
print(dict(map(lambda z,y:(z,list(filter(lambda x:not x.startswith('fruit_'),host[y]))),host,host)))
user9158931
source
share