#------------------------------------------------------------------------------ # convert tuple list to dict value # [(u'type', u'text/javascript'), (u'src', u'http://partner.googleadservices.com/gampad/google_service.js')] # { u'type':u'text/javascript', u'src':u'http://partner.googleadservices.com/gampad/google_service.js' } def tupleListToDict(tupleList): convertedDict = {}; for eachTuple in tupleList: (key, value) = eachTuple; convertedDict[key] = value; return convertedDict;
例 2.18. tupleListToDict 的使用范例
#singleContent: name=script, attrMap=None, attrs=[(u'type', u'text/javascript'), (u'src', u'http://partner.googleadservices.com/gampad/google_service.js')] attrsDict = tupleListToDict(singleContent.attrs);