def test(): # test-1 print ulist.getlen() ulist.listout() print('first is:', ulist.getfirst()) print('last is:', ulist.getlast()) ulist.sort() ulist.listout() ulist.append("qqqq") ulist.listout() ulist.dividing() ulist.insert(1, 'insert') ulist.listout() ulist.dividing() ulist.delfirst() print('first is:', ulist.getfirst()) # test-2 dicttest.cheeseshop('Limburger', "It's very runny, sir.", "It's really very, VERY runny, sir.", shopkeeper='Michael Palin', client="John Cleese", sketch="Cheese Shop Sketch") dicttest.varargs('wjh', ',', 'hebei', 'beijing', 'shanghai') helper.dividing() print dicttest.getdict() print dicttest.getdict2() print dicttest.getdict3()
def test(): # 循环遍历 helper.dividing() for i, v in enumerate(['one', 'two', 'three']): print i, v helper.dividing() for i, v in enumerate([x ** 2 for x in range(0, 5)]): print i, v helper.dividing() basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] for f in sorted(set(basket)): print f helper.dividing() for v in basket: print v helper.dividing() for i, v in enumerate(basket): print i, v # zip helper.dividing() questions = ['name', 'quest', 'favorite color'] answers = ['lancelot', 'the holy grail', 'blue'] for q,a in zip(questions,answers): print 'What is your {0}? It is {1}.'.format(q, a) helper.dividing() knights = {'gallahad': 'the pure', 'robin': 'the brave'} for k,v in knights.iteritems(): print k,v # 切片 words = ['cat','window','difference'] for w in words[:]: if len(w)>6: words.insert(0,w) print words
# file:lambdatest.py # coding:utf-8 __author__ = 'robin' import cn.net.vive.base.helper as helper import cn.net.vive.test.dicttest as dicttest helper.dividing() f = dicttest.make_incrementor(42) print f(0) print f(1) helper.dividing() pairs = [(1, 'one'), (2, 'two'), (3, 'three')] pairs.sort(key=lambda pair: pair[1]) print pairs helper.dividing() alist = range(1, 10) low = 3 high = 6 print filter(lambda x: low < x < high, alist) helper.dividing() def with_bound(value, l=low, h=high): return l < value < h
def test(): # 循环遍历 helper.dividing() for i, v in enumerate(['one', 'two', 'three']): print i, v helper.dividing() for i, v in enumerate([x**2 for x in range(0, 5)]): print i, v helper.dividing() basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] for f in sorted(set(basket)): print f helper.dividing() for v in basket: print v helper.dividing() for i, v in enumerate(basket): print i, v # zip helper.dividing() questions = ['name', 'quest', 'favorite color'] answers = ['lancelot', 'the holy grail', 'blue'] for q, a in zip(questions, answers): print 'What is your {0}? It is {1}.'.format(q, a) helper.dividing() knights = {'gallahad': 'the pure', 'robin': 'the brave'} for k, v in knights.iteritems(): print k, v # 切片 words = ['cat', 'window', 'difference'] for w in words[:]: if len(w) > 6: words.insert(0, w) print words
def listout(dividing=False): if dividing == True: helper.dividing() for i in shoplist: print(i)
# file:lambdatest.py # coding:utf-8 __author__ = 'robin' import cn.net.vive.base.helper as helper import cn.net.vive.test.dicttest as dicttest helper.dividing() f = dicttest.make_incrementor(42) print f(0) print f(1) helper.dividing() pairs = [(1,'one'),(2,'two'),(3,'three')] pairs.sort(key=lambda pair:pair[1]) print pairs helper.dividing() alist = range(1, 10) low = 3; high = 6 print filter(lambda x: low < x < high, alist) helper.dividing() def with_bound(value, l=low, h=high): return l < value < h; print filter(with_bound,alist)