zoukankan      html  css  js  c++  java
  • Sequcences and Sorts in Python介绍

    from operator import itemgetter,attrgetter
    def main():
        #range function
        mynms =list(range(10,20,2))
        print mynms
        print sorted([1,3,5,6,7,1,6,8,5,8,9,6,4,2,2])
        print sorted(['a','h','t','x','b'])
        items =['mikc','alxe','code','good','nice']
        print items.sort()  # this gonna not works
        print sorted(items)
        nums = [6,5,4,3,2,7,2,7,3,2]
        nums.sort()
        print nums   # while this is gonna to work
        bakk = [('books1','a',10),('books2','b',9)]
        print sorted(bakk,key=itemgetter(2),reverse=True)   #itemgetter(2)    0  1
    
    
        # indexing and slicing
        letters ='abcdgfgegege'
        slice1 =letters[1:3]
        slice2 = letters[:3]
        slice3 = letters[1:]
        slice4 = letters[:]
        slice5 = letters[:-1]
        print slice1 , slice2  ,  slice3, slice4 ,slice5
    
        case = ['books','cup','dobule']
        slice12 =case[0:2]   # only 1 not included 2
        print  slice12
    
    
        # sort in place
    
        grocery =['bread','milk','cheese','egg','corn','juice']
        grocery.sort()
        grocery.sort(key=lambda x: x,reverse=True)
        print grocery
        newlist = sorted(grocery)
        print  newlist
    main()

  • 相关阅读:
    Sublime Text配置Python开发利器
    Python字符进度条
    安装和使用的django的debug_toolbar
    Python数组合并
    django创建项目
    Python的闭包
    Python获取对象的元数据
    Python的枚举类型
    Django的Model上都有些什么
    Git使用相关
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501256.html
Copyright © 2011-2022 走看看