def judge(alist):
if any(alist[i+1] <= alist[i] for i in range(0,len(alist)-1)):
return 'No'
else:
return 'Yes'
alist = [1,2,3,4,5,6,7,8,9,10]
print(judge(alist)) # 'Yes'
alist = [1,2,2,4,5,6,8,9,10]
print(judge(alist)) # 'No'
如果是手动实现算法
from functools import reduce
#file = 'not-number-vip.tom.com.txt'
#shunzi = 'shun-vip-due.txt'
file = 'not-number-vip.tom.com.txt'
tonghua = 'tonghua-vip-due.txt'
value = []
def shunzilist(*value):
if value[1:]==value[:-1] and reduce(lambda x,y:x*y,value)==1:
return True
else:
return False
def tonghualist(*value):
if value[1:]==value[:-1]:
return True
else:
return False
with open(file,'r') as file_object:
lines = file_object.readlines()
for line in lines:
line = line.strip()
char_list = list(line)
length = len(char_list)
if length != 1:
res = tonghualist(*char_list)
print(line)
print(res)
if res == True:
with open(tonghua, 'a') as file_object:
file_object.write(line + '\n')
# with open(file,'r') as file_object:
# lines = file_object.readlines()
# for line in lines:
# line = line.strip()
# char_list = list(line)
# length = len(char_list)
# index = 0
# if length != 1:
# while index < length -1:
# number = ord(char_list[index])
# next_number = ord(char_list[index + 1])
# index = index + 1
# sub = next_number - number
# value.append(sub)
# res = shunzilist(*value)
# print(line)
# print(value)
# print(res)
# if res == True:
# with open(shunzi, 'a') as file_object:
# file_object.write(line + '\n')
# value.clear()