Python/自定义排序函数
今天用两种方式来判断输入的值是否为升序降序和无序列三种,包括值重复Number1:#!/usr/bin/env python# -*- coding:utf-8 -*-def RuoLan(value):x = 1R = []for i in range(1,len(value)):if value[i] >= value[i - 1] or val
·
今天用两种方式来判断输入的值是否为升序降序和无序列三种,包括值重复
Number1:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def RuoLan(value):
x = 1
R = []
for i in range(1,len(value)):
if value[i] >= value[i - 1] or value[i] == value[i - 1]:
if value[0] < value[1] or value[0] == value[1]:
R.append('up')
else:
pass
elif value[i] < value[i - 1] or value[i] == value[i - 1]:
R.append('down')
else:
R.append('none')
if 'up' in R and 'down' not in R and 'none' not in R:
print 'up'
elif 'down' in R and 'up' not in R and 'none' not in R:
print 'down'
else:
print 'none'
RuoLan('0123333345')
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def a(x):
if sorted(x) == list(x):
print 'up'
elif list(reversed(sorted(x))) == list(x):
print 'down'
else:
print 'none'
a([7,5,5,5,5,5,3,2])
更多推荐
已为社区贡献12条内容
所有评论(0)