我已经学习Python仅仅几周了,所以请多多包涵。假设我有3个变量:
AX557349 = "gcggatttactcaggggagagcccagataaatggagtctgtgcgtccacagaattcgcacca"
AX557350 = "tccgtgaaacaaagcggatgtaccggatttttattccggctatggggcaattccccgtcgcggagcca"
Tester = "atcgatccblah"
nucs = []
nucs.extend(AX557349, AX557350, Tester)
我只想返回包含“ a”,“ t”,“ c”或“ g”以外的字符的列表元素。在这种情况下,请使用Tester。我将如何去做?
答案 0 :(得分:3)
有两种方法。您可以将all
与生成器表达式一起使用:
def checker(x):
acgt = set('acgt')
return not all(i in acgt for i in x)
或者,使用set.issubset
或它的语法糖<=
:
def checker(x):
return not set(x) <= set('acgt')
结果:
checker(AX557349) # False
checker(AX557350) # False
checker(Tester) # True
答案 1 :(得分:2)
您可以使用Python的any
函数:
var a = Fetchable.success("hi there");
if (a is FetchableSuccess<String>) {
print(a.object); // fine
}
var b = Fetchable<dynamic>.success("hi there");
if (b is FetchableSuccess) {
print(b.object); // fine
}
var c = Fetchable.success("hi there" as dynamic);
if (c is FetchableSuccess) {
print(c.object); // fine
}
答案 2 :(得分:2)
使用一套怎么样?
if len(set(Tester) - set("acgt")) > 0:
print("contains other characters")