question 333 Functional & Dynamic Python · easy
Tidy brand lists
Open Food Facts brand lists come with stray spaces, empty entries and the same brand typed twice in different case: ["Weetabix", " Ready break", "weetabix "]. Write a pure function tidy_brands(brands): strip each brand, drop empty ones, and keep only the first spelling of brands that are equal ignoring case, in order. Don't change the list you're given.
Function
tidy_brands(brands)Returnsa new list, e.g.
["Weetabix", "Ready break"] for the example aboveMust notchange
brandsExamples
calltidy_brands(['Weetabix', ' Ready break', 'weetabix '])returns['Weetabix', 'Ready break']
calltidy_brands(['Nestlé', ' Lion'])returns['Nestlé', 'Lion']
calltidy_brands(['Crownfield', 'Lidl'])returns['Crownfield', 'Lidl']