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实现.

猜你喜欢

转载自www.cnblogs.com/jason-Gan/p/10976716.html