python天天1道面試題(2)--刪除特定字符

"""
題目2:輸入兩個字符串,從第一字符串中刪除第二個字符串中全部的字符。例如,輸入」They are students.」和」aeiou」,
則刪除以後的第一個字符串變成」Thy r stdnts.」。

解題思路: 遍歷第二個字符串中全部的字符,將第一字符串中包含的這個字符所有用''替換

"""


def rm_alp(str, alphabets):
    for alp in alphabets:
        str = str.replace(alp,'')
    print(str)


str = "They are students."
alphabets = 'aeiou'
rm_alp(str, alphabets)
# 輸出: Thy r stdnts.

參考連接:  https://blog.csdn.net/GetNextWindow/article/details/24133695 原文用java實現.java

相關文章
相關標籤/搜索