Here is the output I want to convert from tuples to dict:
(198, [u'http://domain.com', u'http://domain2'])
(199, [u'http://domain3.com/', u'http://www.domain4'])
it should come out like:
(198: [u'http://domain.com', u'http://domain2']),
(199: [u'http://domain3.com/', u'http://www.domain4'])
I tried all kinds of things in for loop:
for item in opa.items():
aa = {(y:[x]) for y,[x] in item}
But always end up getting the same error:
TypeError: 'int' object is not iterable
Even better solution would be to create dict instead of tuples at "creation of output"(using now)
opa = defaultdict(list)
a3 = [model.objects.get(keyword=keyword).url]
for k in a3:
opa[keyword].append(k)
I tried something like this, but it does't 'add' list of domains to key... it just added one:
opa = defaultdict(dict)
a3 = [model.objects.get(keyword=keyword).url] # returns list of urls
for k in a3:
opa[keyword] = [k]