Question:
I have a text
I need to find US and put it at the end: like this
output: 3200 NORTHLINE AVE STE 360GREENSBORO27408-7611 NC US
However, what if I have lookup as a list like below:
and multiple input as a list like below:
I need to find the country for each input list and put it at the end of a string for each list.
I tried many methods but couldn’t do. Your help will be greatly appreciated.
Thanks
Answer:
You can start by breaking the string down into tokens:
If you want to put a country code at the end you can sort the list of tokens using a
key
sort value. Example:
To put this back into a string you can use a join
To make this work for a variety of country codes, you only need to slightly modify the
key
Putting this altogether:
If you have better answer, please add a comment about this, thank you!