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)
Alternatively you can define a dict outside the function, much more compact.

```
def btn_add_printer(self):
    printer = str(self.ui.comboBox.currentText())
    if printer in self.printers: network_printer = printers[printer]

def btn_remove_printer(self):
    printer = str(self.ui.comboBox.currentText())
    if printer in self.printers: network_printer = printers[printer]

self.printers = {
        'printer1_name_short':'printer1_name_long',
        'printer2_name_short':'printer2_name_long',
        'printer3_name_short':'printer3_name_long',
}

```

Or pass the dict:

```
def btn_add_printer(self, printers):
    printer = str(self.ui.comboBox.currentText())
    if printer in printers: network_printer = printers[printer]

def btn_remove_printer(self, printers):
    printer = str(self.ui.comboBox.currentText())
    if printer in printers: network_printer = printers[printer]

printers = {
        'printer1_name_short':'printer1_name_long',
        'printer2_name_short':'printer2_name_long',
        'printer3_name_short':'printer3_name_long',
}

self.btn_add_printer(printers)

```

Or use a helper function:

```
def printerLong(self, printerShort):
    printers = {
        'printer1_name_short':'printer1_name_long',
        'printer2_name_short':'printer2_name_long',
        'printer3_name_short':'printer3_name_long',
    }

    if printerShort in printers:
        return printers[printerShort]

def btn_add_printer(self, printers):
    printer = str(self.ui.comboBox.currentText())
    network_printer = self.printerLong(printer)

def btn_remove_printer(self, printers):
    printer = str(self.ui.comboBox.currentText())
    network_printer = self.printerLong(printer)

```