用字典替换多个单词

时间:2016-03-05 18:57:28

标签: python

 belongs_to :guest, :class_name => 'Guest', :foreign_key => 'guest_id'
 belongs_to :guest2, :class_name => 'Guest', :foreign_key => 'guest2_id'

当我运行程序时,我有这些错误TypeError:sequence item 0:expect str instance,int found.How我能解决吗?

1 个答案:

答案 0 :(得分:0)

您需要sub函数的字符串,以修复您可以将字典的值更改为字符串:

dic1[(char)]=str(position)

或将lambda功能更改为:

result = pattern.sub(lambda x: str(dic[x.group()]), s)