简体   繁体   English

如何从具有特定字母的列表中查找单词?

[英]How do I find words from a list with specific letters?

first list:第一个清单:

word_list = ['Jack','Caroline','Jane']

second list:第二个清单:

letter_list = ['a','c']

I want to save all the words that contain the letters 'a' AND 'c' in a third list.我想将所有包含字母“a”“c”的单词保存在第三个列表中。

The third list should look like this:第三个列表应如下所示:

third_list = ['Jack','Caroline']

You could try this:你可以试试这个:

word_list = ['Jack', 'Caroline', 'Jane']
letter_list = ['a', 'c']

third_list = [word for word in word_list if all(letter in word.lower() for letter in letter_list)]
print(third_list)
# ['Jack', 'Caroline']

暂无
暂无

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

相关问题 (Python)如何将几个字母与整个单词列表进行比较以查找哪些单词按顺序包含搜索的字母? - (Python) How do I compare a few letters to a whole list of words to find, what words contain the searched-for letters in order? 如何查找不包含特定字母的单词? - How to Find Words Not Containing Specific Letters? 如何在列表中交替使用字母/单词的大小写? - How do I alternate the cases of letters/words in a list? 如何从具有字母的行和列中获取单词? - How do i get words from rows and columns having letters? 如何找到列表的特定元素在列表中的距离? 换句话说,特定元素在结果列表中的位置 - How do I find how far in the list a specific element of the list is? In other words, the location of a specific element in a list of results 如何在特定位置生成仅包含特定数量字母的单词列表? - How can I generate a list of words containing only a specific number of letters in specific positions? 如何在字符串列表中找到主要字母 - How do I find the predominant letters in a list of strings 如何在 Python 的 a.txt 文件中查找包含特定字母的单词? - how to find words containing specific letters in a .txt file with Python? 如何从包含特定字母的列表中打印出单词? 我知道如何处理以特定字母开头但不以 BETWEEN 开头的单词 - How can I print out words from a list that contains a particular letter? I know what to do with words starting with specific letter but not in BETWEEN 如何按找到它们的顺序列出它找到的特定单词 - How do I list specific words it finds in the order it finds them in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM