2026年深圳AI算法工程师的面试题集与解析.docxVIP

  • 1
  • 0
  • 约5.46千字
  • 约 15页
  • 2026-03-09 发布于福建
  • 举报

2026年深圳AI算法工程师的面试题集与解析.docx

第PAGE页共NUMPAGES页

2026年深圳AI算法工程师的面试题集与解析

一、编程能力测试(3题,每题10分)

1.Python编程题(10分)

题目:

请编写一个Python函数,实现以下功能:

给定一个字符串`s`,统计其中所有单词的词频,并按词频从高到低排序,返回排序后的词频列表。假设单词由空格分隔,忽略大小写和标点符号。

示例输入:

`s=Helloworld!Thisisatest.Hello,world!`

示例输出:

`[(hello,2),(world,2),(this,1),(is,1),(a,1),(test,1)]`

答案与解析:

python

importre

fromcollectionsimportCounter

defword_frequency(s):

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

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

words=s.split()

统计词频

counter=Counter(words)

按词频排序

sorted_freq=counter.most_common()

returnsorted_freq

示例

s=Helloworld!Thisisatest.Hello,world!

print(word_

文档评论(0)

1亿VIP精品文档

相关文档