m0_56754186 2021-05-19 19:17 采纳率: 0%
浏览 116

python找出英文中长度为4个字母的单词并输出,要求去除重并以字典顺序输出列表

编写程序,找出下列英文中所有长度为4个字母的单词并输出,要求去除重复的单词并以字典顺序输出,输出为列表的形式,如3个字母的单词,输出为:

['For', 'One', 'See', 'The', 'Use', 'You', 'and', 'any', 'are', 'bit', 'can', 'cpp', 'etc', 'for', 'gcc', 'has', 'how', 'int', 'may', 'not', 'one', 'out', 'run', 'see', 'std', 'the', 'try', 'use', 'was', 'you']

提示:假设输出列表为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 readable indentation.

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.

Never use control flow without curly braces ( if ,  else ,  do ,  while ,  for , etc.)

Use  <stdbool.h> ,  bool ,  true , and  false to represent boolean values.

Never compare with  true , e.g. never  == true .

Do not leave commented-out code in your code.

Provide comments for anything that's not totally and completely obvious.

Always check to see if I/O functions were actually successful.

On an unexpected error, print out a useful error message and exit the program.

For invalid input from the user you should handle it by asking the user to try again or by exiting the program with  exit(1) ,  exit(2) , etc. or

returning 1 or 2 etc. from main.

For unexpected errors, such as fgets failing to read anything, consider  abort() .

Main must only return 0 if the program was successful.

Do not use magic literals (magic numbers or magic strings).

If a value has a particular meaning, give a meaningful name with  #define or by declaring a constant with  const .

Values other than 0 and 1 with the same meaning must not appear more than once.

0 or 1 with a meaning other than the immediately obvious must also be given a name.

String literals must not appear more than once.

This includes magic numbers that appear in strings!

Program must compile without warnings with  gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 .

Program must be architecture-independent:

Program must not rely on the sizes of int, long, size_t, or pointers.

Program must compile without warnings with  gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 -m32 . Note the added -m32!

The result of this compilation must be an executable program.

The 32-bit program must produce the same output as the 64-bit program.

Program must be compiler-independent:

Program must compile without warnings with  clang .

You can use the same options for  clang that you use for  gcc !

Program compiled with  clang should produce the same output as when it's compiled with  gcc .

Code must be lint-free:

Program must pass  clang-tidy --checks=* without warnings, except those which are explicitly allowed.

Currently allowed:

cert-err34-c

cert-msc30-c

cert-msc50-cpp

More allowed warnings may be added. Check eClass for updates.

See instructions on how to run the linters below.

Program must pass  oclint without warnings, except those which are explicitly allowed.

Currently allowed:

UselessParentheses

我的解答为:

import re
text=input()
pattern=re.compile(r'\b[a-zA-Z]{4}\b')
total=(pattern.findall(text))
set1=(total)
list0=set(set1)
list1=sorted(list0)
print(list1)

自己顺便输入一段英文,可以正确输出结果,但将题干中英文带入却出现错误,请问那一步存在问题呀?刚学python新手小白虚心请教大佬,请不要用函数解,因为看不懂QAQ,就用正则表达式就可

  • 写回答

2条回答 默认 最新

  • CSDN专家-林老师 2021-05-19 19:37
    关注

    你这个题目看着太乱了,你要不重修修改一下吧。

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧