A Few Things to Remember While Coding in Python
[i=s] 本帖最後由 jieforest 於 2012-5-21 10:24 編輯
halve_evens_only = lambda nums: map(lambda i: i/2, filter(lambda i: not i%2, nums))
#-----------------------------------------------------------------------
def halve_evens_only(nums):
return [i/2 for i in nums if not i % 2]
Zen of Python
Learning theculture that surrounds a language brings you one step closer to being a betterprogrammer. If you haven’t read the Zen of Python yet open a Python prompt andtype import this. For each of the item on the list you canfind examples herehttp://artifex.org/~hblanks/talks/2011/pep20_by_example.html
One caught my attention:
Beautifulis better than ugly
Give me a function that takes a list ofnumbers and returns only the even ones, divided by two.
CODE:
#-----------------------------------------------------------------------halve_evens_only = lambda nums: map(lambda i: i/2, filter(lambda i: not i%2, nums))
#-----------------------------------------------------------------------
def halve_evens_only(nums):
return [i/2 for i in nums if not i % 2]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-730670/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python while/forPythonWhile
- Python配合Redis寫個Remember小工具PythonRedisREM
- python while迴圈PythonWhile
- python_while truePythonWhile
- 四、python之 if while forPythonWhile
- python-while迴圈PythonWhile
- Python的流程控制 - whilePythonWhile
- python中的while...elsePythonWhile
- python中while 1表示什麼PythonWhile
- 15-python之while迴圈PythonWhile
- 【雜談】Remember-Me的實現REM
- Shiro中的Remember me設定REM
- [Cexpert-003] You should remember some of ASCII!REMASCII
- Python基礎-While迴圈語句PythonWhile
- Python學習-while迴圈練習PythonWhile
- python基礎 (3)if 和 while的使用PythonWhile
- python基礎 while迴圈練習PythonWhile
- Python基礎——while、字串、列表及操作PythonWhile字串
- Afterall most women on quite a few skillUI
- 【Python基礎知識】Python中的while語句PythonWhile
- Python中的if、while、for 語法及例項PythonWhile
- Python 中的for,if-else和while語句PythonWhile
- Do Evil Things with gopher://Go
- Python的編碼註釋# -*- coding:utf-8 -*-Python
- Java 迴圈 - for, while 及 do…whileJavaWhile
- Spring Security 之 Remember-Me (記住我)SpringREM
- If you cannot remember your password for Recovery and Rescue for IBM LaptopREMIBMAPT
- Python趣味入門5:迴圈語句whilePythonWhile
- Python的if else 巢狀 和forin while 迴圈Python巢狀While
- 【廖雪峰python入門筆記】while迴圈Python筆記While
- python學習手冊13:while及for迴圈PythonWhile
- while迴圈以及do while迴圈While
- python 中的 for-else 和 while-else 語句PythonWhile
- Java:運用while()與do....while與for()JavaWhile
- Java迴圈結構-for,while及do…whileJavaWhile
- Java while和do while迴圈詳解JavaWhile
- All good things come to an endGo
- do-while語句和while的區別While