from collections import Counter, OrderedDict import warnings from vcinema_utils import VCinemaUtils warnings.filterwarnings("ignore") def get_actor_scores(viewings): for viewing_ind in range(len(viewings)): viewing = viewings[viewing_ind] cast_list = [] for cast_member in viewing['cast']: cast_member_name = (cast_member['name'], cast_member.currentRole) cast_list.append(cast_member_name) viewings[viewing_ind]['cast'] = cast_list viewings_filtered_by_cast_member = VCinemaUtils.filter_viewings(viewings, "cast") viewings_filtered_by_cast_member = OrderedDict(sorted(viewings_filtered_by_cast_member.items(), key=lambda t: len(t[1]), reverse=True)) return viewings_filtered_by_cast_member