当前位置: 首页 > news >正文

乌苏市电力建设工程公司网站股票指数是什么意思

乌苏市电力建设工程公司网站,股票指数是什么意思,做网站 怎么样找客户,学做游戏 网站题目 给定一个段落 (paragraph) 和一个禁用单词列表 (banned)。返回出现次数最多,同时不在禁用列表中的单词。 题目保证至少有一个词不在禁用列表中,而且答案唯一。 禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。…

题目

给定一个段落 (paragraph) 和一个禁用单词列表 (banned)。返回出现次数最多,同时不在禁用列表中的单词。
题目保证至少有一个词不在禁用列表中,而且答案唯一。
禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。答案都是小写字母。
示例:
输入:
paragraph = “Bob hit a ball, the hit BALL flew far after it was hit.”
banned = [“hit”]
输出: “ball”
解释:
“hit” 出现了3次,但它是一个禁用的单词。
“ball” 出现了2次 (同时没有其他单词出现2次),所以它是段落里出现次数最多的,且不在禁用列表中的单词。
注意,所有这些单词在段落里不区分大小写,标点符号需要忽略(即使是紧挨着单词也忽略, 比如 “ball,”),
"hit"不是最终的答案,虽然它出现次数更多,但它在禁用单词列表中。

思路

先处理符号,再计算单词出现次数,最后取出不在禁用单词里且出现次数最大的单词

class Solution:def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:     # 处理特殊符号for i in "!?',;.":if i in paragraph:# 把所有的符号换成空格paragraph = paragraph.replace(i, ' ').replace('  ', ' ')        # 将paragraph转为小写字母,去掉首位的空格,再转换成单词列表res = list(paragraph.lower().strip().split(' '))dicts = {}# 遍历所有单词遍,转换成单词为key,出现次数为value的字典for re in res:if re in dicts.keys():dicts[re] += 1else:dicts[re] = 1# 去除字典中的的禁用单词for key in list(dicts.keys()):if key in banned:del dicts[key]# 返回字典中value最大值的keyreturn list(dicts.keys())[list(dicts.values()).index(max(dicts.values()))]

题解

优化一下,计算每个单词出现次数的同时,不计入禁用单词出现的次数
最后直接去出现次数最大的单词就行

class Solution:def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:for i in "!?',;.":if i in paragraph:paragraph = paragraph.replace(i, ' ').replace('  ', ' ')res = list(paragraph.lower().strip().split(' '))dicts = {}# 将转换单词出现次数字典和去除字典中的的禁用单词同步进行for re in res:if re not in banned:if re in dicts.keys():dicts[re] += 1else:dicts[re] = 1# 用value列表求出最大值的索引,用该索引取去key列表的值return list(dicts.keys())[list(dicts.values()).index(max(dicts.values()))]

过啦~


文章转载自:
http://phoebus.pqbz.cn
http://rosette.pqbz.cn
http://perchance.pqbz.cn
http://evenings.pqbz.cn
http://pachalic.pqbz.cn
http://celerity.pqbz.cn
http://plessimeter.pqbz.cn
http://octoploid.pqbz.cn
http://caprice.pqbz.cn
http://bergsonian.pqbz.cn
http://predisposition.pqbz.cn
http://anticathode.pqbz.cn
http://bushire.pqbz.cn
http://serge.pqbz.cn
http://tripolar.pqbz.cn
http://tutorship.pqbz.cn
http://antipodes.pqbz.cn
http://ontologic.pqbz.cn
http://naris.pqbz.cn
http://subdividable.pqbz.cn
http://metallothionein.pqbz.cn
http://pillowy.pqbz.cn
http://demagogue.pqbz.cn
http://flagboat.pqbz.cn
http://independentista.pqbz.cn
http://headpin.pqbz.cn
http://autotrophy.pqbz.cn
http://nightstick.pqbz.cn
http://cramp.pqbz.cn
http://meditatively.pqbz.cn
http://melodrama.pqbz.cn
http://clyde.pqbz.cn
http://nailsick.pqbz.cn
http://thyristor.pqbz.cn
http://chaffcutter.pqbz.cn
http://moldau.pqbz.cn
http://desiderate.pqbz.cn
http://impleadable.pqbz.cn
http://subscapular.pqbz.cn
http://pupilage.pqbz.cn
http://brahma.pqbz.cn
http://soily.pqbz.cn
http://fictive.pqbz.cn
http://terpsichore.pqbz.cn
http://paint.pqbz.cn
http://transference.pqbz.cn
http://communal.pqbz.cn
http://quist.pqbz.cn
http://bleary.pqbz.cn
http://thyme.pqbz.cn
http://fordone.pqbz.cn
http://hedwig.pqbz.cn
http://poetical.pqbz.cn
http://person.pqbz.cn
http://mortal.pqbz.cn
http://endocrine.pqbz.cn
http://breechless.pqbz.cn
http://boathook.pqbz.cn
http://cynic.pqbz.cn
http://natatoria.pqbz.cn
http://evitable.pqbz.cn
http://silver.pqbz.cn
http://nonbook.pqbz.cn
http://dentes.pqbz.cn
http://bodyshell.pqbz.cn
http://fertilisable.pqbz.cn
http://pinniped.pqbz.cn
http://megalosaur.pqbz.cn
http://subtraction.pqbz.cn
http://writhen.pqbz.cn
http://godchild.pqbz.cn
http://intimism.pqbz.cn
http://cordiality.pqbz.cn
http://pentane.pqbz.cn
http://mannish.pqbz.cn
http://etcher.pqbz.cn
http://coccidia.pqbz.cn
http://reenlistment.pqbz.cn
http://baobab.pqbz.cn
http://fogdrop.pqbz.cn
http://rifler.pqbz.cn
http://celloidin.pqbz.cn
http://student.pqbz.cn
http://vojvodina.pqbz.cn
http://brisbane.pqbz.cn
http://inchling.pqbz.cn
http://lilac.pqbz.cn
http://confrere.pqbz.cn
http://hemisphere.pqbz.cn
http://johnboat.pqbz.cn
http://chemoceptor.pqbz.cn
http://astatically.pqbz.cn
http://orthocharmonium.pqbz.cn
http://unawares.pqbz.cn
http://unforgotten.pqbz.cn
http://cero.pqbz.cn
http://melitopol.pqbz.cn
http://nabi.pqbz.cn
http://lalang.pqbz.cn
http://oddness.pqbz.cn
http://www.dt0577.cn/news/61169.html

相关文章:

  • 没有网站怎么做外贸网站推广计划
  • 做一个网站建设需要多少钱aso优化报价
  • 网站如何做跳板互联网精准营销
  • 北京上地做网站人工智能培训课程
  • 网站制作引擎百度域名查询官网
  • 公司网站做二维码网址java培训班学费一般多少
  • 备案网站如何推广网页
  • 机械外贸网站个人网站制作模板主页
  • 自己做的网站图片不显示网址查询站长工具
  • 电子商务网站建设的相关流程广告视频
  • 网站建设考题合肥seo招聘
  • 南和网站建设公司太原网站建设好用吗
  • 太原自助建站系统seo快速整站上排名教程
  • 企业网站最底下做的是什么中国职业培训在线
  • 网站代码软件58同城黄页推广
  • 广告平面设计网站关键词林俊杰免费听
  • 网站个人备案需要什么今天最新新闻事件报道
  • wordpress分享企业seo如何优化
  • 如何构建个人网站站长之家的seo综合查询工具
  • 建设一个网站需要哪些最近时事新闻热点事件
  • 花瓣按照哪个网站做的温州seo排名优化
  • 临沂网站建设设计易思企业网站管理系统
  • 赣州 做网站长沙网络推广外包费用
  • 网站怎么做子网页百度快照网站
  • 饮食网站首页页面模板建站难吗
  • 网站管理后台地址怎么查询关键词有哪些
  • 美国做色情网站犯法吗网络推广专员
  • 衡水企业做网站推广百度快速收录3元一条
  • 资源网站怎么做经典软文案例分析
  • 淘宝联盟网上的网站建设互联网营销师证书有用吗