I have a dict
containing another dict
inside it
d1 = {'a':{'p':1, 'q':2, 'r':'abc'},
'b':{'p':5, 'q':6, 'r':["google", "pypi.org"]}
}
url1 = "https://google.com"
url2 = "https://abc.com"
Now what I want to do is run a check on values of r
from both the dict values
but I don't want any code redundancy.How is that possible ?
What I am doing right now is :-
for k, v in d1.iteritems():
if isinstance(v['r'], list):
for l in v['r']:
if url1.find(l):
..Do something..
else:
continue
else:
if url1.find(v['r'):
..Do Something same as above..
else:
continue
Now the problem arises with the same Do something
repeated 2 times , Is there a way to solve redundancy with comprehension or by any other method , except function making and calling .
Edit-- The code is already inside a large function definition , so do provide other solutions than making another function and calling it.