grt=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","decillion","undecillion","duodecillion","tredecillion","quattuor-decillion","quindecillion","sexdecillion","septen-decillion","octodecillion","novemdecillion","vigintillion"]
e=["sixty","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion"]
def sep():
global e
global grt
for i in range(1,len(e)):
if (e[i] in grt and e[i-1] in grt)==True:
e.remove(e[i])
while all(((i in grt) and (e[e.index(i)-1] in grt)) for i in e[1:len(e)])!=False:
sep()
print(e)
我希望最后一条语句print(e)会打印[“ sixty”],但不会打印出来。
答案 0 :(得分:0)
过滤功能非常适合此类应用。
grt=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","decillion","undecillion","duodecillion","tredecillion","quattuor-decillion","quindecillion","sexdecillion","septen-decillion","octodecillion","novemdecillion","vigintillion"]
e=["sixty","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion"]
results = list(filter(lambda x: x not in grt, e))
print(results)