今天用两种方式来判断输入的值是否为升序降序和无序列三种,包括值重复

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])
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐