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

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

如何操作二維列表

如何操作二維列表

HUX布斯 2022-04-23 21:53:29
我需要幫助為我的計(jì)算 GCSE NEA(未經(jīng)檢查的評(píng)估)處理二維列表,我需要做的是在一行(一首單曲)上顯示每首歌曲標(biāo)題的第一個(gè)字母以及藝術(shù)家姓名,例如 AC/ DC 'Back in Black' 將是 'B i B' AC/DC我通常堅(jiān)持如何操作數(shù)組以顯示我需要的內(nèi)容,并且我使用了幾個(gè)網(wǎng)站,例如 snakify 和其他一些網(wǎng)站到目前為止,這是我的程序:stageone=[['another one bites the dust','Queen',           'smoke on the water','Deep Purple',           'Stairway to heaven','Led Zeppelin',           'Carry on wayward son','Kansas',           'Don't stop believin','Journey']]mainmenu=input("Welcome to the game please select an option-s for start the game,ts for top scores,ys for your scores,n for new game")if mainmenu=='s':  play=input("do you want to continue you last game-c or do you want to start   a new game-n?")  if play=='s':    difficulty=input("What difficulty do you want to play? you can choose     from; easy,medium,difficult and legend")    if difficulty=='easy':       print("The easy mode of this game contains five stages,each with five        questions")       sure=input("Are you sure you want to play this gamemode?")       if sure=='y':       print(stageone)我需要這首歌是獨(dú)立的,而不是整個(gè)陣列。每首歌都需要每個(gè)單詞的第一個(gè)字母,而不是整個(gè)單詞。我不知道如何編寫程序的這一部分,我們將不勝感激。歌曲藝人名但必須是完整的而不是單一的,首字母如歌名
查看完整描述

1 回答

?
哈士奇WWW

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

當(dāng)您定義 stageone 時(shí),使其成為如下列表的列表:


stageone = [[title, band], [title, band], [title, band]]


然后,而不是print(stageone)在最后一行做:


for entry in stageone:

    shortTitle = ' '.join([word[0] for word in entry[0].split(' ')])

    print(shortTitle, entry[1])

更新:要一次獲得一個(gè)提示,您需要一些方法來(lái)選擇一個(gè)條目stage one(對(duì)于游戲,我想這可能是一個(gè)隨機(jī)索引)。然后你只需刪除for我之前給出的循環(huán)并像這樣使用你選擇的條目


i = #some code to select an entry in stageone

entry = stageone[i]

shortTitle = ' '.join([word[0] for word in entry[0].split(' ')])

print(shortTitle, entry[1])

請(qǐng)注意,有很多方法可以使它更緊湊,但最初的問(wèn)題讓我認(rèn)為更冗長(zhǎng)的答案比最小的解決方案更好。例如,@calestinifor在我的第一個(gè)回復(fù)中評(píng)論了一個(gè)單行來(lái)替換循環(huán),


res = [[' '.join([x[0] for x in i[0].split()]), i[1]] for i in stageone ]

這是一個(gè)很好的解決方案 -res將是一個(gè)列表[[song hint, band name], [song hint, band name]],然后您可以根據(jù)需要打印提示。我沒(méi)有改變我原來(lái)的答案,因?yàn)槲也幌矚g在一行中使用兩個(gè)列表推導(dǎo)(我很難閱讀代碼)。


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

添加回答

舉報(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)