[英]python- with an undetermined tuple (str), how to find if a letter is in each one of the strings
So basically, the user is allowed to input any amount of strings that they want to when they call the function, as long as the it's a string and the strings are separated by commas and have quotation marks around them. 因此,基本上,允许用户在调用函数时输入他们想要的任意数量的字符串,只要它是一个字符串并且字符串之间用逗号分隔并在其周围加上引号即可。 For example: 例如:
func("str1", "str2", "str3")
I want to look at each one of these strings that they put in and see if it contains a specific character, like the letter 'a' for example. 我想查看他们放入的每个字符串,看看它是否包含特定字符,例如字母“ a”。 If they all contain the letter, I want to return true, if they don't, I want to return false. 如果它们都包含字母,我想返回true,否则,我想返回false。 How can I look at each of the strings they put in (because there is no specified amount) and check? 我如何查看它们放入的每个字符串(因为没有指定数量)并检查?
def func(*args):
return all('a' in str(x) for x in args)
def func(*args):
if not all([isinstance(x,basestring) for x in args]):return False
return reduce(lambda x,y:set(x).intersection(y),args)
might give you the info you want 可能会给您您想要的信息
"a" in func("str1", "str2", "str3") == False
"s" in func("str1", "str2", "str3") == True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.