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

相关文章
相关标签/搜索