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

全字母短句 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("")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值