日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python从字典里搜索_Python:在字典中搜索字典的函数

發布時間:2024/9/3 python 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python从字典里搜索_Python:在字典中搜索字典的函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有個問題是這樣的Write the contract, docstring and implementation for a function findActor that takes a movie title and a character's name and returns the actor/actress that played the given character in the given movie. If the given movie or the given character is not found, it prints out an error message and returns an empty string

我已經完成了以下功能,這些功能將有助于實現這一點。myIMDb是一個全局字典,設置為一個空的dic來啟動def addMovie (title, charList, actList):

"""The function addMovie takes a title of the movie, a list of characters,

and a list of actors. (The order of characters and actors match one

another.) The function addMovie adds a pair to myIMDb. The key is the title

of the movie while the value is a dictionary that matches characters to

actors"""

dict2 = {}

for i in range (0, len(charList)):

dict2 [charList[i]] = actList[i]

myIMDb[len(myIMDb)] = {title: dict2}

return myIMDb

def listMovies():

"""returns a list of titles of all the movies in the global variable myIMDb"""

titles = []

for i in range (len(myIMDb)):

titles.append((list(myIMDb[i].keys())))

return titles

這就是我的問題所在。當我想寫findActor函數時,我沒有得到任何可返回的東西。我還沒有完成這個功能,但我認為我做了一些根本性的錯誤。我覺得自己走錯了路,越寫越迷路。這就是我的目的。如有任何關于如何糾正這艘沉船的建議,我們將不勝感激。在

^{pr2}$

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的python从字典里搜索_Python:在字典中搜索字典的函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。