【搞笑】如何寫出別人看不懂自己也看不懂的代碼


寫在前面:

  話說那是很久以前,代碼交付按行收費,於是程序員們盡量寫出更多行的代碼。但自古以來就是道高一尺魔高一丈,於是興起另一個職業---縮行師。縮行師的職責,就是去掉程序猿代碼里多余的代碼,將代碼的行數盡量降到最低。剝削和反剝削的階級斗爭從來就沒有停止過,直到代碼交付不再以行數計費。

  至於有興趣了解縮行師職業的人,可以戳一下這里:縮行師職業簡介

  現如今,天下大勢以定,若是能穿越從前,我一定能當一名高級縮行師,下面聽我慢慢道來。

高級縮行師實踐指南:

  第一回合

  程序猿提交代碼

# 將列表中每個數+1,返回新的List
def add_one(data):
    data_new = []
    for i in data:
        new = i+1
        data_new.append(new)
    return data_new
    

  縮行師說:

def add_one(data):
    return [i+1 for i in data]

  第二回合

  程序猿提交代碼

# 條件判斷
def case(condition):
    if condition:
        return 'result_true'
    else :
        return 'result_false'

  縮行師說

  

def case(condition):
    return 'result_true' if (condition) else 'result_false'

  

   第三回合

  程序猿提交代碼

def get_content(content):
    content = content.decode('utf8')
    beautiful = BeautifulSoup(content,'lxml')
    divs = beautiful.find_all('div')
    contents_div = []
    for div in divs:
        cont = div.contents
        if len(cont) == 1:
            contents_div.append(cont[0])
    result = ''
    for cont in contents_div:
        result += cont
    return result

  縮行師說

def get_content(content):
    ''.join([div.contents[0] if(len(div.contents)==1) else '' for div in BeautifulSoup(content.decode("utf8"),'lxml').find_all('div')])

  

 

 

 

 

 

  后面想起來了慢慢更新……我是占位符占位符占位符……

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM