I have a two dictionaries:
nums = {u'+123456789': [u'google.com', u'yahoo.com', u'183.6.43.21'], u'+9876543210': [u'amazon.com', u'yahoo.com', u'bit.ly'] ... }
that contains phone number and domains linked to this number
and
availability = {u'yahoo.com': 0.3, u'amazon.com': 0.0, u'183.6.43.21': 0.0, u'bit.ly': 0.9, u'google.com': 1.0}
I need to attach this dictionaries together, so I can send sms to each phone number contains text with domains availability.
I make a function, that can do that:
for key, value in nums.iteritems():
for domain, av in availability.iteritems():
if domain in value:
if key in dct:
a = dct[key], domain
dct.update({key: a})
else:
dct[key] = domain
for key in dct:
send_to(phone=key, text=dct[key])
It works, but when the only one domain attached to phone number in nums - it comes as a string, and sometimes output can looks like that:
Send to: +1234567890
(((u'183.23.45.65', u'google.com'), u'yahoo.com'), u'bit.ly')
Is there any way to generate the tuple with the only one layer? Or maybe the best way is to recursively open this tuple?