> attributes = ['foo', 'bar'] > > attributeNames = {} > n = 1 > for attribute in attributes: > attributeNames["AttributeName.%d" % n] = attribute > n = n + 1 > > It works, but I am wondering if there is a more pythonic way to > do this.
"Better" may be subjective, but you could do something like attributes = ['foo', 'bar'] attributeNames = dict( ("AttributeName.%d" % (i+1), attrib) for i, attrib in enumerate(attributes) ) HTH, -tkc -- http://mail.python.org/mailman/listinfo/python-list