Question: Given the following two strings:

```
let subject: &str = "zoop-12";
let trail: &str "-12";

```

How would I go about removing `trail` from `subject` only once? I would only like to do this in the case that `subject` has these characters at its end, so in a case like this I would like nothing removed:

```
let subject: &str "moop-12loop";
let not_a_trail: &str = "-12";

```

I'm okay with either being a `String` or `&str`, but I choose to use `&str` for brevity.

Answer: 
You can use a dictionary to assign the `printerX_name_long`.

```
def get_network_printer(name_short):
    return {
    printer1_name_short: printer1_name_long,
    printer2_name_short: printer2_name_long
    }.get(name_short, "default")

def btn_add_printer(self):
    network_printer = get_network_printer(self.ui.comboBox.currentText())

```

This is assuming you want to avoid multiple if-else statements. Otherwise, the answer by Chris suits better.

More possible relevant answers [here](https://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python)
So since both functions use exactly the same code you could create a function that does this code, and then call that function from the other two. something like 

```py
class my_class:
    def btn_add_printer(self):
        self.printer_func()

    def btn_remove_printer(self):
        self.printer_func()

    def printer_func(self):
        printer = str(self.ui.comboBox.currentText())
        if printer == printer1_name_short:
            network_printer = printer1_name_long
        elif printer == printer2_name_short:
            network_printer = printer2_name_long
        elif printer == printer3_name_short:
            network_printer = printer3_name_long

        #not sure what you want to do with network_printer but can do it here

```