runtime
333 / 500
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.

Functiontidy_brands(brands)
Returnsa new list, e.g. ["Weetabix", "Ready break"] for the example above
Must notchange brands
Examples
calltidy_brands(['Weetabix', ' Ready break', 'weetabix '])returns['Weetabix', 'Ready break']
calltidy_brands(['Nestlé', ' Lion'])returns['Nestlé', 'Lion']
calltidy_brands(['Crownfield', 'Lidl'])returns['Crownfield', 'Lidl']

Loading your progress…

Tidy brand lists — Python practice · Runtime