Question: I am writing a function that returns a list of car models. The input is a string of comma separated cars. Duplicate entries are not added to the result. The elements in the list should be in the same order as they appear in the input string. If the input string is empty, the result is an empty list. I modified it to support multiple model names, e.g. `print(car_models("Tesla Model S,Skoda Super Lux Sport))` gives `['Model S', 'Super Lux Sport']`.

```
def car_models(all_cars: str) -> list:
    if not all_cars:
        return []
    all_models = []
    cars = all_cars.split(",")
    for car in cars:
        unique_car = car.split(" ")
        if unique_car[1] not in all_models:
            all_models.append(" ".join(unique_car[1:]))
    return all_models

```

While testing the code, an error occurred:
[![enter image description here](https://i.stack.imgur.com/QlYDw.png)](https://i.stack.imgur.com/QlYDw.png)

And I can't figure out what's wrong, can anyone tell me how to fix it?

Answer: 
Since you're appending `" ".join(unique_car[1:])` to the list, you need to use the same thing when checking if already exists.

Solve this easily by assigning that to a variable, so you can use the same thing in the `in` test and `append()` call.

```
def car_models(all_cars: str) -> list:
    if not all_cars:
        return []
    all_models = []
    cars = all_cars.split(",")
    for car in cars:
        car_words = car.split(" ")
        model = " ".join(car_words[1:])
        if model not in all_models:
            all_models.append(model)
    return all_models

```
First, I suppose you misspelled the command and should be like:

> 
> print(car\_models("Tesla Model S","Skoda Super Lux Sport"))
> 
> 
> 

And then, instead of:

```
unique_car = car.split(" ")

```

I should use something like:

```
unique_car = car[car.find(" ")+1:]

```

to have full name of the model compared. Even with:`unique_brand = car[:car.find(" ")]` you can be able to create a beautiful dictionary like: `{'brand1':[model1, model2], 'brand2':...}`

Besides, if the problem is coming from the test, please share your test code.