2026年人工智能系统开发面试题及答案.docxVIP

  • 1
  • 0
  • 约5.52千字
  • 约 14页
  • 2026-03-19 发布于福建
  • 举报

2026年人工智能系统开发面试题及答案.docx

第PAGE页共NUMPAGES页

2026年人工智能系统开发面试题及答案

一、编程实现题(共3题,每题20分,总分60分)

1.(20分)编写一个Python函数,实现以下功能:给定一个包含多个单词的字符串,统计每个单词出现的频率,并按频率从高到低排序输出。要求不区分大小写,忽略标点符号。

答案:

python

importre

fromcollectionsimportCounter

defword_frequency(text):

去除标点符号并转换为小写

cleaned_text=re.sub(r[^\w\s],,text).lower()

words=cleaned_text.split()

word_counts=Counter(words)

sorted_words=sorted(word_counts.items(),key=lambdax:x[1],reverse=True)

returnsorted_words

示例输入

text=Helloworld!Helloeveryone.Thisisatest,asimpletest.

print(word_frequency(text))

解析:

-使用正则表达式`re.sub`去除标点符号,并将所有字母转换为小写以统一统计。

-`C

文档评论(0)

1亿VIP精品文档

相关文档