找出字符串中缺失字母,并按字母顺序排序输出

全字母短句 PANGRAM 是包含所有英文字母的句子,比如:A QUICK BROWN FOX JUMPS OVER THE LAZY DOG. 定义并实现一个方法 get_missing_letter, 传入一个字符串采纳数,返回参数字符串变成一个 PANGRAM 中所缺失的字符。应该忽略传入字符串参数中的大小写,返回应该都是小写字符并按字母顺序排序(请忽略所有非 ACSII 字符)
下面示例是用来解释,双引号不需要考虑:
(0)输入: “A quick brown fox for jumps over the lazy dog”
返回: “”
(1)输入: “A slow yellow fox crawls under the proactive dog”
返回: “bjkmqz”
(2)输入: “Lions, and tigers, and bears, oh my!”
返回: “cfjkpquvwxz”
(3)输入: “”
返回:“abcdefghijklmnopqrstuvwxyz”

import string
tem = string.ascii_lowercase
def get_missing_letter(s):  #考虑重复字母
    res = ""
    for i in tem:
        if i not in s:
            res += i
    print(res)
get_missing_letter("A quick brown fox for jumps over the lazy dog")
get_missing_letter("A slow yellow fox crawls under the proactive dog")
get_missing_letter("Lions, and tigers, and bears, oh my!")
get_missing_letter("")
import string
tem = string.ascii_lowercase
def get_missing_letter(s):
    res = set(tem)-set(s)
    print("".join(sorted(res)))        

get_missing_letter("A quick brown fox for jumps over the lazy dog")
get_missing_letter("A slow yellow fox crawls under the proactive dog")
get_missing_letter("Lions, and tigers, and bears, oh my!")
get_missing_letter("")
上一篇:实现自动批量上传/更新测试用例到TestLink工具


下一篇:三本的我面试微软,微软包机票酒店早餐到苏州,实在太棒了