hackerrank for python程序的所有测试用例都失败

2024-05-01 16:34:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,其中任务是根据练习完成的,并且给出了要执行的某些步骤。即使输出匹配,但我得到了失败的测试用例,甚至没有一个实现

函数调用:stringmethod("我们的知识来自于我们的知识,来自于我们的精英,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识索利西图丁和奥古斯都坐在一起。他们坐在一起是因为我们的元素。他们坐在一起是因为我们的朗卡斯,威尼斯人的爱欲,奥古斯。他们坐在一起是因为我们的需要。他们需要我们的知识。他们的生命之光,尊严之光,美丽之光。他们是非猫科动物,奥古斯都人,我们的朋友。暂时性的潜在性悬置,智者和奥纳雷·普莱斯特拉特,智者毛里斯·卢库斯·萨皮恩,在前庭秃鹫前的一个和另一个水平。悬置生命的悬置。悬置!舌苔、苏打水和猫科植物的叶缘。不可替代的,不可替代的,不可替代的我们,等等,莫利斯·努拉。尼西的拉奥里特修女坐在一张桌子上,他说:“我爱你,我爱你,我爱你,我爱你,我爱你,我爱你,我爱你,我爱你。” ,“3”, [“再见”, “Aliquam”, “Suspendisse”, “vulputate”],“vulputate”)

from collections import Counter



def stringmethod(para, special1, special2, list1, strfind):
    # 1. remove all the special characters given in special1
    word1= ''.join([word for word in para if word not in special1])
    
    #2getting frst 70 and reversing from word1
    word2 = word1[:70]
    rword2= word2[::-1]
    print(rword2)
    
    #3.1removing white spaces from rword2
    rword2 = rword2.replace(" ","")
    #3.2joining the characters using special 2
    joint_string= special2.join(rword2)
    print(joint_string)
    
    #4. checking list1 with para 
    
    if (i in para for i in list1):
        print(f"Every string in {list1} were present")
    else:
        print(f"Every string in {list1} were not present")
        
    #5. splitting word from word1 and printing first 20 strings
    
    word1_split= word1.split()
    print(word1_split[:20])
    
    #frequency less than 2 using counter
    word_counter= Counter(word1_split)
    
    #making a temporary list to store split words for less than 3
    temp=[]
    for k,v in word_counter.items():
        if v<3:
            temp.append(k)
        else:
            pass
    #6. last 20 frequent words from temp
    last_20_words= temp[-20:]
    print(last_20_words)
    
    
    #7. print last index in word1 where substring strfind is found 
    
    print(word1.rfind(strfind))

原始输入: 我们的知识来自于我们的知识,来自于我们的精英,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识,来自于我们的知识索利西图丁和奥古斯都坐在一起。他们坐在一起是因为我们的元素。他们坐在一起是因为我们的朗卡斯,威尼斯人的爱欲,奥古斯。他们坐在一起是因为我们的需要。他们需要我们的知识。他们的生命之光,尊严之光,美丽之光。他们是非猫科动物,奥古斯都人,我们的朋友。暂时性的潜在性悬置,智者和奥纳雷·普莱斯特拉特,智者毛里斯·卢库斯·萨皮恩,在前庭秃鹫前的一个和另一个水平。悬置生命的悬置。悬置!舌苔、苏打水和猫科植物的叶缘。不可替代的,不可替代的,不可替代的我们,还有莫利斯·努拉。尼西的拉奥里特修女坐在一张桌子上,脸上的皱纹只是因为爱神的爱。她是我的修女。她是我的修女,她是侵权者。 ,@%\$。 , 3. 告别 等分 悬钩子 胡说八道

enter image description here


Tags: infromforstringtempwordsplitwords