如何用其他东西替换元组中的元素?

时间:2017-04-25 15:41:49

标签: python nlp

我是编程的新手,我需要用python进行一些文本处理,我需要做的是替换元组中的元素。我已经有一个看起来像这样的元组列表

my_list=[('the','b'),('apple','i'),('is','o'),('delicious','o')]

并且我想更改元组中的第二个元素,如果第二个元素是'b'或'i',我想将其更改为'yes',如果元组中的第二个元素是'o' ,然后什么都不做。

我很想知道在python中是否有一些漂亮而干净的方法。 非常感谢你。

1 个答案:

答案 0 :(得分:0)

  

如果第二个是' o'或者'我想将其改为“是”'
  如果元组中的第二个元素是' o',则不执行任何操作。

你提到" o"两次在这里,所以我假设其中一个是" b"的错字。我假设如果第二个元素是" o",那么什么都不做,否则第二个元素应该变成"是"。

CodeMod.sendMail(strTo, strFrom, "Test Email", "Test Content",, Server.MapPath("/Test/TEST.pdf"))

---------------------------------
Public Sub sendMail(strTo As String, strFrom As String, strSubject As String, strMsg As String, Optional ByVal strCc As String = "", Optional ByVal file As String = "")

Dim oMMsg As New Net.Mail.MailMessage()
oMMsg.From = New MailAddress(strFrom)
oMMsg.To.Add(strTo)
oMMsg.Subject = strSubject
oMMsg.Body = strMsg
oMMsg.IsBodyHtml = True

If file <> "" Then oMMsg.Attachments.Add(New Attachment(file))

Dim client As New SmtpClient()
client.Host = "correct.information"
client.Port = 25
client.Send(oMMsg)

End Sub