def find_parents(candidate, branches):
 for branch in branches:
  try:
   idx = branch.index(candidate.lower())
   return list(reversed(branch[:(idx + 1)]))
  except ValueError:
   continue
 return [candidate]

def find_parents ( candidate , branches ) : for branch in branches : try : idx = branch . index ( candidate . lower ( ) ) return list ( reversed ( branch [ : ( idx + 1 ) ] ) ) except ValueError : continue return [ candidate ]
find parents genre of a given genre .