On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
Hello,

I'd like to define variables with some specific name that has a common
prefix.
Something like this:

varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iteritems():
'myPrefix' + key = value


No trick, just swap a new key-value pair for each existing pair:

  for key, value in varDic.iteritems():
      varDic[myPrefix + key] = value
      del varDict[key]

Just make sure that *myPrefix* isn't an empty string!

-John
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to