python - Using a conditional comprehesion and the re.search function to find all the strings in a list?
问题描述
I'm trying to use a conditional comprehesion and the re.search function to find all the strings in DNA_list that start with 'ATG' and end with 'TAG'
DNA_list = ['GTCTCTCGA', 'ATGCCTGAAGCATTCTAG', 'GCTGCCCACAAG', 'ATGACTGTAAAACCCTAG']
import re
dna=[print(element)for element in DNA_list if re.search(r'(^ATG)(TAG$)',str(DNA_list))]
But I don't get an output. What am I missing?
解决方案
result = [s for s in DNA_list if re.match(r'^ATG.*TAG$', s)]
推荐阅读
- javascript - How do we clear an angular dropdown list value in angular?
- powershell - How to replace any character different from others previously specified?
- java - how to fix LayoutInflater error in java android?
- python - Python Telnetlib验证登录不起作用
- npm - `npm install @babel/cli` 对四个模块说“WARN deprecated”。我该如何解决这些弃用?
- python-3.x - 字符串格式在 python Tkinter 文本小部件中不起作用
- python - 从 Python 文件运行 Jupyter Notebook
- flutter - 在 null 上调用了方法 cancel
- python - 规范化 Tensorflow 对象检测 API 的输入
- python - Xpath 命令 - 返回另一个类的第三个实例中的类的第二个实例的内容?