Even though the answer was accepted, I thought I would include for reference an example of how you should be using join() instead of adding strings together. This also shows you that its avoiding None values:
d = {u'a': u'a', u'c': None, u'b': u'b', u'e': None, u'd': None, u'g': u'g', u'f': u'f', u'i': u'i', u'h': u'h', u'k': u'k', u'j': u'j', u'm': None, u'l': u'l', u'o': u'o', u'n': None, u'p': u'p'}
resolve = ''.join((value for value in d.itervalues() if value is not None))
print resolve
# u'abgfihkjlop'
And if what you wanted to do was only loop over a predetermined set of keys:
keys = ('c', 'g', 'f', 'm')
''.join([v for v in (d[k] for k in keys) if v is not None])
Here is a test showing the difference between this approach, appending to a list, and adding strings together:
from time import time
d = {}
for i in xrange(1000):
v = u'v%d' % i
d[v] = v
def test1():
return ''.join(v for v in d.itervalues() if v is not None)
def test2():
result = []
for v in d.itervalues():
if v is not None:
result.append(v)
return ''.join(result)
def test3():
result = ''
for v in d.itervalues():
if v is not None:
result += v
return result
def timeit(fn):
start = time()
r = fn()
end = time() - start
print "Sec:", end, "msec:", end*1000
>>> timeit(test1)
Sec: 0.000195980072021 msec: 0.195980072021
>>> timeit(test2)
Sec: 0.000204086303711 msec: 0.204086303711
>>> timeit(test3)
Sec: 0.000397920608521 msec: 0.397920608521
You can see that when your loops get bigger it really makes a difference.
foois obviously some kind of django Query object or a pymongo wrapper that acts like a defaultdict, and returns None for missing keys. There is nothing wrong with adding an ascii and unicode (though in a loop its bad, you should join).resolveis obviously None and you need to check your values.