简体   繁体   English

python-具有未确定的元组(str),如何查找每个字符串中是否包含字母

[英]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.

相关问题 Python-计算单词列表中的每个字母 - Python- Count each letter in a list of words Python- For Loop-增加列表中每个元组的每个索引位置 - Python- For Loop - Increment each index position for each tuple in list 在 Python 中编程 Discord 机器人 - 当消息仅包含一个字母时,如何让它识别? - Programming a Discord bot in Python- How do I make it recognize when a message contains only one letter? Python 2.7:如何查找字符串中每个单词的第一个字母的索引 - Python 2.7: how to find the index of the first letter of each word in a string Python 打字:元组[str] vs 元组[str, ...] - Python typing: tuple[str] vs tuple[str, ...] 在大文件中查找字符串,并将每个字符串写入Python中的第二个文件 - Find strings in a large file and write each one to a second file in Python Python-如何比较访问数据库和变量之间的字符串? - Python- How to compare strings between an access db and a variable? Python-如何返回一个字典,用于计算字符串列表中的出现次数? - Python- How to return a dictionary that counts occurrences in a list of strings? Python- twitterstream。 过滤元组错误 - Python- twitterstream. filter tuple error Python-从 txt 文件创建元组 - Python- Creating a tuple from a txt file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM