简体   繁体   English

如何确保刺出现在列表中的某处

[英]How to make sure the sting appear in somewhere in the list

enter image description here Write a function that takes,as an argument,a list and a string, and returns a Boolean based on whether or not all of the letters in the string appear somewhere in the list.在此处输入图像描述编写一个函数,该函数接受一个列表和一个字符串作为参数,并根据字符串中的所有字母是否出现在列表中的某个位置返回一个布尔值。 For question 3对于问题 3

def findLetters(myList,myString): for i in myList: if i==myString: return True return False That is what did in python, but if I run python shell it constantly give False. def findLetters(myList,myString): for i in myList: if i==myString: return True return False 这就是在 python 中所做的,但是如果我运行 python shell,它会不断给出 False。

Looks like homework task.看起来像家庭作业。 It is fairly simple so try it yourself.这是相当简单的,所以你自己试试吧。 Use operator in to check if a letter is in a string.使用运算符in检查字母是否在字符串中。

if c in string:
    print(c, 'is in', string)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM