Python - 用另一个替换单词 [英] Python - replace word with another

查看:195
本文介绍了Python - 用另一个替换单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有12个单元格的html表。每个单元格都有一个要替换的单词。所有的话都是一样的。我还有一个包含12个元素的列表。每个元素都是一个单词。我需要用列表中的相应单词替换每个单词。第一个单词用第一个元素替换,第二个用第二个元素替换,依此类推。你能给我举个例子吗,我是python的新手?

I have html table with 12 cells. Each cell has a word to be replaced. All of the words are identical. Also I have a list with 12 elements. Each element is a word. I need to replace each word with the appropriate word from the list. First word to be replaced with the first element, second with the second element and so on. Can you give me an example how to do this, I'm new at python?

推荐答案

words = ['fist','second','thrid']

for word in words:
    yourText = yourText.replace('theOldWord',word,1)

这篇关于Python - 用另一个替换单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆