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

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

在Python的大數(shù)組中尋找“打印”的位置?

在Python的大數(shù)組中尋找“打印”的位置?

天涯盡頭無女友 2023-10-18 11:07:04
我正在學(xué)習(xí)如何從數(shù)組中獲取數(shù)據(jù),并且我有點(diǎn)陷入一種簡單的方法來定位數(shù)據(jù)從數(shù)組中提取數(shù)據(jù)的位置。感覺應(yīng)該有比在屏幕上數(shù)更簡單的方法。這是我所擁有的:r2 = requests.get(    f'https://www.thesportsdb.com/api/v1/json/{apiKey}/lookupevent.php?id={id}')arr_events = np.array([r2.json()])#print(arr_events)event_id = arr_events[0]['events'][0]['idEvent']locate = arr_events.index('strHomeTeam')print(locate)問題是,在控制臺上打印出一個巨大的數(shù)組,看起來像(我將給出一行,你可能明白了):[{'events': [{'idEvent': '1032723', 'idSoccerXML': None, 'idAPIfootball': '592172', 'strEvent': 'Aston Villa vs Liverpool', 'strEventAlternate': 'Liverpool @ Aston Villa', 'strFilename': 'English Premier League 2020-10-04 Aston Villa vs Liverpool'...}]}]這是一個相當(dāng)大的數(shù)組,如果我需要提取一些信息,足以導(dǎo)致輕微的速度減慢。因此,使用上面的方法很容易拉取 idEvent。如果我想要其中一些位于頂行,可能不難數(shù)到 5 或 6。但我知道 Python 必須有一種更簡單的方法來定位我想要的那些。例如,我想要主隊(duì)和客隊(duì):'strHomeTeam': 'Aston Villa', 'strAwayTeam': 'Liverpool',那么有沒有一種更簡單的方法來拉動“strHomeTeam”而不是一直計(jì)數(shù)到數(shù)組中的點(diǎn)呢?我意識到這是一個基本問題 - 我已經(jīng)搜索了又搜索,但所有內(nèi)容似乎都在一個非常小的數(shù)組中,并且它們似乎沒有解釋如何輕松地從大數(shù)組中獲取數(shù)據(jù)。JSON 文件位于:https://www.thesportsdb.com/api/v1/json/1/lookupevent.php ?id=1032723感謝您對此的幫助 - 我很感激。
查看完整描述

3 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個贊

那么有沒有一種更簡單的方法來拉動“strHomeTeam”而不是一直計(jì)數(shù)到數(shù)組中的點(diǎn)呢?


嘗試下面的方法


data = {"events": [

    {"idEvent": "1032723", "idSoccerXML": "", "idAPIfootball": "592172", "strEvent": "Aston Villa vs Liverpool",

     "strEventAlternate": "Liverpool @ Aston Villa",

     "strFilename": "English Premier League 2020-10-04 Aston Villa vs Liverpool", "strSport": "Soccer",

     "idLeague": "4328", "strLeague": "English Premier League", "strSeason": "2020-2021",

     "strDescriptionEN": "Aston Villa and Liverpool square off at Villa Park, where last season, these teams produced one of the most exciting finishes of the campaign, as Liverpool scored twice late on to overturn an early Trezeguet goal.",

     "strHomeTeam": "Aston Villa", "strAwayTeam": "Liverpool", "intHomeScore": "7", "intRound": "4",

     "intAwayScore": "2", "intSpectators": "", "strOfficial": "", "strHomeGoalDetails": "", "strHomeRedCards": "",

     "strHomeYellowCards": "", "strHomeLineupGoalkeeper": "", "strHomeLineupDefense": "",

     "strHomeLineupMidfield": "", "strHomeLineupForward": "", "strHomeLineupSubstitutes": "",

     "strHomeFormation": "", "strAwayRedCards": "", "strAwayYellowCards": "", "strAwayGoalDetails": "",

     "strAwayLineupGoalkeeper": "", "strAwayLineupDefense": "", "strAwayLineupMidfield": "",

     "strAwayLineupForward": "", "strAwayLineupSubstitutes": "", "strAwayFormation": "", "intHomeShots": "",

     "intAwayShots": "", "strTimestamp": "2020-10-04T18:15:00+00:00", "dateEvent": "2020-10-04",

     "dateEventLocal": "2020-10-04", "strDate": "", "strTime": "18:15:00", "strTimeLocal": "19:15:00",

     "strTVStation": "", "idHomeTeam": "133601", "idAwayTeam": "133602", "strResult": "", "strVenue": "Villa Park",

     "strCountry": "England", "strCity": "", "strPoster": "", "strFanart": "",

     "strThumb": "https:\/\/www.thesportsdb.com\/images\/media\/event\/thumb\/r00vzl1601721606.jpg", "strBanner": "",

     "strMap": "", "strTweet1": "https:\/\/twitter.com\/brfootball\/status\/1312843172385521665",

     "strTweet2": "https:\/\/twitter.com\/TomJordan21\/status\/1312854281444306946",

     "strTweet3": "https:\/\/twitter.com\/FutbolBible\/status\/1312847622592442370",

     "strVideo": "https:\/\/www.youtube.com\/watch?v=0Nbw3jSafGM", "strStatus": "Match Finished", "strPostponed": "no",

     "strLocked": "unlocked"}]}

filtered_data = [{'home':entry['strHomeTeam'],'away':entry['strAwayTeam']}for entry in data['events']]

print(filtered_data)

輸出


[{'home': 'Aston Villa', 'away': 'Liverpool'}]


查看完整回答
反對 回復(fù) 2023-10-18
?
慕無忌1623718

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

呃......我嘗試了一些不同的東西,它起作用了 - 嘆息......我很抱歉。


event_id = arr_events[0]['events'][0]['idEvent']

home_team = arr_events[0]['events'][0]['strHomeTeam']

away_team = arr_events[0]['events'][0]['strAwayTeam']

home_score = arr_events[0]['events'][0]['intHomeScore']

away_score = arr_events[0]['events'][0]['intAwayScore']

我認(rèn)為這是正確的方法。


查看完整回答
反對 回復(fù) 2023-10-18
?
白豬掌柜的

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個贊

查看完整回答
反對 回復(fù) 2023-10-18
  • 3 回答
  • 0 關(guān)注
  • 267 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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