List Comprehensions: a concise way to create lists,,# List compr
List Comprehensions: a concise way to create lists,,# List compr
# List comprehensions provide a concise way to create lists without resorting to use # of map(), filter() and/or lambda. freshfruit = [' banana', ' loganberry ', 'passion fruit ']print [weapon.strip() for weapon in freshfruit]vec = [2, 4, 6]print [3*x for x in vec]print [3*x for x in vec if x > 3]print [3*x for x in vec if x < 2]print [[x,x**2] for x in vec]print [(x, x**2) for x in vec]vec1 = [2, 4, 6]vec2 = [4, 3, -9]print [x*y for x in vec1 for y in vec2]print [x+y for x in vec1 for y in vec2]print [vec1[i]*vec2[i] for i in range(len(vec1))]print [str(round(355/113.0, i)) for i in range(1,6)]
- Catch several exceptions,severalexceptions,class MyErr
- Loop over two or more sequences at the same time,loops
- Exception handlers handle Exceptions occur inside functi
- Draw Arc,drawarc,from Tkinter
- Indexing a single-item tuple,single-itemtuple,print (
- User-defined Exceptions: Name their own exceptions by cr
热门文章:
相关内容
- Catch several exceptions,severalexceptions,class MyErro
- Loop over two or more sequences at the same time,loopsequences,# Lo
- Exception handlers handle Exceptions occur inside functions.,handle
- Draw Arc,drawarc,from Tkinter
- Indexing a single-item tuple,single-itemtuple,print ('x',
- User-defined Exceptions: Name their own exceptions by creating a new
- This is a simple web tree checker, useful to find bad links in a web
- Map: lambda function inside,maplambda,foo = [2, 18
- Python模拟http post,python模拟post,import sys,
- oct and hex function,octhex,print oct(64
评论关闭