Great answer @Lars60+. I thnk the newlines should be replaced by vertical bars before parsing (see 'Adventure\n' in line one).
from collections import Counter data = 'Genres\nAction|Adventure\nAction|Adventure|Animation\nAction|Adventure|Animation|Comedy|Drama\n' \ 'Action|Adventure|Animation|Comedy|Family\nAction|Adventure|Animation|Drama|Family\n' \ 'Action|Adventure|Animation|Family\nAction|Adventure|Animation|Family|Fantasy\n' \ 'Action|Adventure|Animation|Family|Mystery\nAction|Adventure|Animation|Family|Science Fiction\n' \ 'Action|Adventure|Animation|Fantasy\nAction|Adventure|Animation|Fantasy|Horror\n' \ 'Action|Adventure|Animation|Fantasy|Science Fiction\n' data_list = data.replace('\n', '|') data_list = data_list.strip().split('|') print(Counter(data_list).most_common(1))
Output:[('Action', 12)]
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00