Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我想访问字典中的所有键并检查键(ATGC)之类的序列是否具有“GC”。如何访问密钥以检查它是否包含字符串“GC”?
非常感谢!
matches = [ k for k in yourdictionary.keys() if 'gc' in k.lower() ] number_of_matches = len(matches)
你也可以做一个regexor string.find(如果没有找到则返回 -1 )或string.count-- 但if substring in string可以工作并且更清楚地说明这一点。我还将密钥转换为小写并与小写字符串进行比较,因此它可以有效地进行不区分大小写的匹配。
regex
string.find
string.count
if substring in string