首页 > 编程知识 正文

passion函数,getprivateprofilestring函数

时间:2023-05-03 13:54:13 阅读:111798 作者:106

33559 www.hacker rank.com/challenges/iterable s-and-iterators/problem

problem

theitertoolsmodulestandardizesacoresetoffast,memoryefficienttoolsthatareusefulbythemselvesorincombination.together, theyformaniteratoralgebramakingitpossibletoconstructspecializedtoolssuccinctlyandefficientlyinpurepython。

toreadmoreaboutthefunctionsinthismodule,check out their documentation here。

youaregivenalistoflowercaseenglishletters.foragiveninteger,youcanselectanyindices (基于assume的索引) withauniformping

findtheprobabilitythatatleastoneoftheindicesselectedwillcontaintheletter 3360‘’。

输入格式

theinputconsistsofthreelines.thefirstlinecontainstheinteger,denotingthelengthofthelist.thenextlineconsistsofspace-space

thethirdandthelastlineofinputcontainstheinteger,denotingthenumberofindicestobeselected。

输出格式

outputasinglelineconsistingoftheprobabilitythatatleastoneoftheindicesselectedcontainstheletter 3360’。

note : theanswermustbecorrectupto3decimal places。

约束条件

allthelettersinthelistarelowercaseenglishletters。

样本输入

4

acd、acd

2

样本输出

0.8333

解决方案:

fromitertoolsimportcombinationsn=int (l=input (l=input ).split (k=int ) input ) ) c=list (组合) ) d=list (过滤器(lambdax : ' a ' inx,c ) ) (打印) ({0:4f} ).format ) ) l

打印(列表(组合([ 1,2,3 ],2 ) )

result : [ (1,2 ),1,3 ),2,3 ] ]

filter将函数应用于后续列表

print (list (过滤器(lambdaa : a 2,[ 1,2,5,6,0 ] ) )

result [ 5,6 ]

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。