2021-05-23 22:39
采纳率: 100%
浏览 30


Python大佬解题:找出下列英文中所有长度为4个字母的单词并输出。 python list Python编写程序,找出下列英文中所有长度为4个字母的单词并输出,要求去除重复的单词并以字典顺序输出,输出以列表的形式。提示:假设输出列表为list1,则输出语句为:print(list1)。 英文如下:Code Quality Standards Your code must meet the code quality standards. If you've taken CMPUT 174 before these should be familiar to you. Use readableindentation. Blocks must be indented (everything between { and } ) One line must not have more than one statement on it. However, a long statement should be split into multiple lines. Use only idiomatic for loops. Use descriptive variable names. It must be obvious to the person reading (and marking your code) what each variable does. Never use complicated switch logic. Each case must fall through immediately to the next without running any code, or it must run some code and then break out of the switch statement. Never use goto.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • String name="小吴"; 2021-05-23 23:25


    点赞 打赏 评论
  • String name="小吴"; 2021-05-24 18:39
    import re
    dictt = {}  # 声明一个空字典
    word = '''Code Quality Code Standards Your codech variable do'''
    word = re.findall(r'[a-zA-Z]{4}', word)  # 匹配出符合条件的单词
    for i in word:
        if i in dictt:
            dictt[i] += 1  # 如果单词在字典里,单词的数量就加1
            dictt[i] = 1  # 否则就单词数量就 等于 1
    #     循环次数                 set 将单词转为集合(集合自动去除重复单词)
    # for Quantity,i in enumerate(set(word)):
    #     print(Quantity,i)
    点赞 打赏 评论