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之 if while forPythonWhile
- python while迴圈PythonWhile
- python_while truePythonWhile
- python-while迴圈PythonWhile
- Python的流程控制 - whilePythonWhile
- python中的while...elsePythonWhile
- Shiro中的Remember me設定REM
- 15-python之while迴圈PythonWhile
- python中while 1表示什麼PythonWhile
- 【雜談】Remember-Me的實現REM
- Do Evil Things with gopher://Go
- Python學習-while迴圈練習PythonWhile
- Python基礎——while、字串、列表及操作PythonWhile字串
- Python基礎-While迴圈語句PythonWhile
- python基礎 while迴圈練習PythonWhile
- python基礎 (3)if 和 while的使用PythonWhile
- 【Python基礎知識】Python中的while語句PythonWhile
- Spring Security 之 Remember-Me (記住我)SpringREM
- Python 中的for,if-else和while語句PythonWhile
- Python中的if、while、for 語法及例項PythonWhile
- 圓方樹 useful things
- Python的if else 巢狀 和forin while 迴圈Python巢狀While
- 【廖雪峰python入門筆記】while迴圈Python筆記While
- Python趣味入門5:迴圈語句whilePythonWhile
- 正式釋出Android Things 1.0Android
- Android Things 開發入門Android
- Java 迴圈 - for, while 及 do…whileJavaWhile
- Happy coding ! lol?APP
- Things 3 for mac :Things 3是一款流行的任務管理應用程式Mac
- python 中的 for-else 和 while-else 語句PythonWhile
- while迴圈以及do while迴圈While
- The Coding Kata: FizzBuzzWhizz in Scala
- Java迴圈結構-for,while及do…whileJavaWhile
- Java while和do while迴圈詳解JavaWhile
- Java:運用while()與do....while與for()JavaWhile
- python04: while迴圈語句 break continue for in 迴圈PythonWhile
- python:運用while迴圈怎麼進行終止PythonWhile