我试图做一个zip list
查找和替换,使用另一个列表,但由于某种原因,我似乎无法得到我的头,而不是easy
问题。所以,首先,我有一个拉链列表,它看起来像(说myzip_list
):列表查找和替换元素在另一个列表
("this is a united string divided here","this is the value of the string),("this is a multiply string2 united here","this is the value of the string2)....
现在
,我还有一个列表,它看起来像这样(说replace_list
):
[['united', '##sharp'], ['divided', '##blunt'], ['multiply', '##med']]
我想要做的是将myzip_list
[0]元素替换为double hash
,值为replace_list
。因此,作为一个最终的结果,我想直到结束:
myzip_list = ("this is a ##sharp string ##blunt here","this is the value of the string),("this is a ##med string2 ##sharp here","this is the value of the string2)....
希望如果有人也许可以点我在正确的方向...
编辑
网络的如果replace_list
只包含一个单词,下面的答案实际上是有效的。因此,例如,如果replace_list
样子:
[['united all', '##sharp'], ['divided me', '##blunt'], ['multiply all', '##med']]
如果myzip_list
样子:
("this is a united all string divided me here","this is the value of the string),("this is a multiply all string2 united all here","this is the value of the string2)....
..然后Cybers方法失败。
问题是我的'''实际上是一个'zip列表'。当我实现你的解决方案时,我得到'AttributeError:'元组'对象没有属性'split'' – JohnJ 2014-08-30 18:32:08
哦好吧我看到了这个问题。编辑我的帖子。 – CoryKramer 2014-08-30 18:36:17
非常感谢你@Cyber - 它完美的工作,我喜欢它,因为它基本上是一个班轮:)接受你的答案。再次感谢 - 为我节省了大量的时间。 – JohnJ 2014-08-30 18:55:10