飄逸的python,飄逸python

來源:互聯網
上載者:User

飄逸的python,飄逸python

根據題意,我們不能用到if/else/for/while等關鍵字.


--------------思考中------------


思路:

1.用遞迴實現迴圈

2.遞迴的終止條件不用if怎麼判斷呢?  答案是字典,其中用not not n來把數字n轉成bool.


上代碼:

def sum_(n):    return n + {            True:lambda:sum_(n-1),            False:lambda:0        }[not not n]()print sum_(100)




python現在的前景?

現在很多公司都要求 除了會一種靜態語言之外,再掌握一種指令碼語言如perl,shell,python.
因為在工作中經常需要用到指令碼語言開發一些小程式,原因就是指令碼語言文法簡單,方便程式員快速解決問題。
python 可以用來開發,可以用來作管理指令碼。
豆瓣網就是用python開發的。
至於做python的薪水就不好說了,根據你的所在的公司的情況而定。
 
助python的for迴圈

看題看錯,我再想
==========
做出,運行環境python 3.2,>3.0可運行
import functools
def occurrences(text1, text2):
#一行流代碼,利用字典統計text2中所含text1的數量
s_items=dict(map(lambda i:(i[0],text2.count(i[0])),dict( zip(text1,[0]*len(text1))).items()))
print(s_items) #輸出過程 就是你所的“1個'e', 3個'l', 2個'o', 1個'd'”,這行可刪掉
#合并輸出統計總和
return functools.reduce(lambda x,y:x+y, s_items.values())
print(occurrences('fooled','hello world'))
==================
輸出
{'f': 0, 'e': 1, 'd': 1, 'o': 2, 'l': 3}
7
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.