-1

I want to return a list of strings, as shown below:

def get_regions():
    normalized_regions = []
    regions = [
        "auckland"
        "bay of plenty"
        "canterbury"
        "gisborne"
        "hawkes bay"
        "manawatu-whanganui"
        "marlborough"
        "northland"
        "otago"
        "southland"
        "taranaki"
        "tasman"
        "waikato"
        "wellington"
        "west coast"
    ]

    for r in regions:
        normalized_regions.append(normalize_location(r))
    return normalized_regions

normalize_location() is a function that converts the string to lowercase and removes unnecessary white spaces.

I don't understand why append() is concatenating the elements as single string instead of adding them to the list? Please see the screenshot below:

enter image description here

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137

1 Answers1

0

You're going to kick yourself. It's because you haven't got a comma after each entry in the list. Your list should be:

regions = [
    "auckland",
    "bay of plenty",
    "canterbury",
    "gisborne",
    "hawkes bay",
    "manawatu-whanganui",
    "marlborough",
    "northland",
    "otago",
    "southland",
    "taranaki",
    "tasman",
    "waikato",
    "wellington",
    "west coast",
]
Salaah Amin
  • 382
  • 3
  • 14