[英]needing to remove single characters and numbers python
def removePunctuation(emails):
cleanedEmails = [email.translate(str.maketrans('', '', string.punctuation)) for email in emails]
return cleanedEmails
上面的代碼可以看到。 我需要從電子郵件中刪除單個字符和數字。 這將用於 email 垃圾郵件分類。 我以前使用過(沿着這些線不記得確切的代碼)。 代碼本身已經刪除了標點符號,但是由於標點符號的刪除方式,這就是為什么我在刪除單個字符和數字時遇到困難的原因。
''.join(I for I in emails if i.isaplha() and I == 1)
但是,由於代碼更改為翻譯等,我無法開始工作
試圖盡可能地理解這個問題,我認為這是正確的,根據需要調整第 2 行。
def removePunctuation(emails):
punctuation = '!"£$%^&*()'
cleanedEmails = [email.translate(str.maketrans('', '', punctuation)) for email in emails]
return cleanedEmails
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.