第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python中遞歸函數(shù)的解釋

Python中遞歸函數(shù)的解釋

九州編程 2021-07-03 04:29:59
我是 Python 的新手,并試圖將我的頭放在遞歸函數(shù)上。我理解整體概念,但我遇到了一個(gè)我似乎無(wú)法完全理解它在做什么的例子。對(duì)正在發(fā)生的事情進(jìn)行逐步細(xì)分將是理想的,請(qǐng)?zhí)崆案兄x您的幫助。def anagrams(s):    if s == '':            return [s]    else:        ans = []        for w in anagrams(s[1:]):             for pos in range(len(w)+1):                ans.append(w[:pos] + s[0] + w[pos:])    return ans  
查看完整描述

2 回答

?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

def anagrams(s):

    # if argument <s> is a blank String

    if s == '':

        # return a list is just <s> in it

        return [s]

    else:

        # create a List

        ans = []

        # for each String character in calling this function recursively,

        # but removing character 0!

        for w in anagrams(s[1:]): 

            # for character position number starting at 0 and ending at

            # the length of the returned value of the recursed function

            # plus 1

            for pos in range(len(w)+1):

                # append a string with the following concatenation:

                # - the returned value's string from position 0 to position <pos>

                # - the character at position 0 of <s>

                # - the returned value's string from position <pos> to the end

                ans.append(w[:pos] + s[0] + w[pos:])

    # return the list

    return ans 


查看完整回答
反對(duì) 回復(fù) 2021-07-06
  • 2 回答
  • 0 關(guān)注
  • 146 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)