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

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

如何用python編碼方式編寫我的代碼?

如何用python編碼方式編寫我的代碼?

繁星淼淼 2022-04-27 16:03:25
我用 python 寫了一個(gè)原始代碼,我怎樣才能讓它看起來更像一個(gè) python 結(jié)構(gòu),我還沒有為每個(gè)函數(shù)創(chuàng)建類和對象,我想返回而不是打印我怎樣才能明智地分離功能并在最后返回?with open(r'features.csv', 'r') as f:checker = lambda i: bool(i and i.strip())reader = csv.reader(f)header = next(reader)folders = next(    {        header[0]: [row[0]],        'Feature Name': list(filter(checker, row[:1])),        'Child folder': list(filter(checker, row[1:]))    } for row in reader)foldersinlist = list(folders.values())lists = sum(foldersinlist, [])print(lists)有什么想法嗎?
查看完整描述

1 回答

?
九州編程

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

如果我們知道您要如何處理返回的數(shù)據(jù)會(huì)很有幫助,我們可以為您提供更多幫助,但這應(yīng)該會(huì)讓您朝著正確的方向前進(jìn)。


def my_function():

    with open(r'features.csv', 'r') as f:

    checker = lambda i: bool(i and i.strip())

    reader = csv.reader(f)

    header = next(reader)

    folders = next(

        {

            header[0]: [row[0]],

            'Feature Name': list(filter(checker, row[:1])),

            'Child folder': list(filter(checker, row[1:]))

        } for row in reader

    )

    foldersinlist = list(folders.values())

    lists = sum(foldersinlist, [])

    # print(lists) #Instead of this, let's return the value:


    return lists


my_data = my_function() #we're setting my_data to the returned-value of my_function


print (my_data) #Now you can us my_data wherever you need the result of my_function


查看完整回答
反對 回復(fù) 2022-04-27
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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