您好,我遇到了一个问题,我必须列出一个列表并在这些列表中找到各个乐队,看看他们是否都有一个共同喜欢的乐队。如果是这样,我应该输出true。我需要遵循这种编程方法来模块化我的代码,但我似乎无法理解它。到目前为止,这是我的代码。感谢您提供的所有帮助。
favoriteBandLists = [["Metallica","Linkin Park","Alice In Chains","Nirvana", "Soundgarden"],
["Pink Floyd","Alice In Chains","Soundgarden","Metallica","Linkin Park"],
["Audioslave","Offspring","The Beatles", "Soundgarden"]]
def commonFavoriteBand(favoriteBandLists):
thereExists= False
for i in (favoriteBandLists[2]):
if(commonFavoriteBandA(favoriteBandLists)):
thereExists = True
return (thereExists)
def commonFavoriteBandA(favoriteBandLists):
foundCounterExampleYet = False
for band in favoriteBandLists[2]:
if not(band == favoriteBandLists[0:1]):
foundCounterExampleYet = True
return not foundCounterExampleYet
print(commonFavoriteBand(favoriteBandLists))