안녕하세요 저는 목록의 목록을 가져 와서 목록 내의 개별 밴드를 찾아서 모두가 가장 좋아하는 밴드가 있는지 확인해야하는 문제가있었습니다. 그렇다면 사실을 출력해야합니다. 내 코드를 모듈화하는 프로그래밍 방법을 따라야하지만 코드를 얻을 수는 없습니다. 지금까지 제 코드가 있습니다. 당신이 줄 수있는 모든 도움에 감사드립니다. 목록 당신이,지도, 필터 또는 감소와 같은 기능을 가로 지르는 목록 중 하나를 사용할 수 있습니다 통과해야하는 경우일반적인 즐겨 찾기 밴드 파이썬
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))
나는 그것을 할 수 없다. 맨 위에 주어진리스트는 그대로 있어야한다. – Nota4rizzle
시도 :'bool (reduce (lambda x, y : x.intersection (y), favoriteBandsList의 l에 대해 (l) 설정)) ' – tmr232
목록을 재정의 할 필요가 없습니다. 세트를 만듭니다. 예를 들어'set (favoriteBandLists [0])'을 실행하면 첫 번째 목록을 집합으로 가져올 수 있습니다 –