I need to split a string into two variables. For example, the following would work fine:
first,second = "red,blue".split(',')
I would like to split user input, which might have an optional space after the comma. How do I write it so a space after the comma is absorbed? I need to correctly handle all these possibilities:
"red,blue" # first="red" second="blue"
"red, blue" # first="red" second="blue"
"red,dark blue" # first="red" second="dark blue"
"red, light blue" # first="red" second="light blue"
Just trim the resulting entries. The way you do this depends on whether you want to support exactly one space after the comma, or whether you want to remove all leading whitespace (and maybe trailing whitespace too). If your goal is to get words, like it looks like in your sample, you should just remove all surrounding whitespace.