I have the following dictionary
dict1 ={"city":"","name":"yass","region":"","zipcode":"",
"phone":"","address":"","tehsil":"", "planet":"mars"}
I am trying to create a new dictionary that will be based on dict1 but,
- it will not contain keys with empty strings.
- it will not contain those keys that I dont want to include.
i have been able to fulfill the requirement 2 but getting problem with requirement 1. Here is what my code looks like.
dict1 ={"city":"","name":"yass","region":"","zipcode":"",
"phone":"","address":"","tehsil":"", "planet":"mars"}
blacklist = set(("planet","tehsil"))
new = {k:dict1[k] for k in dict1 if k not in blacklist}
this gives me the dictionary without the keys: "tehsil", "planet" I have also tried the following but it didnt worked.
new = {k:dict1[k] for k in dict1 if k not in blacklist and dict1[k] is not None}
the resulting dict should look like the one below:
new = {"name":"yass"}