There are numerous ways to address this issue, some of which have already been raised here. A Google search for "python replace multiple strings" will yield even more ideas, some of them with fairly in-depth discussions.
If you want to stick with using the Field Calculator, then you are going to have to use code blocks. Another option would be to use ArcPy cursors, the Data Access ones are the newest and best.
An approach I have used in the past that is simple, and seems to perform well enough with my data sets, is a variation of a suggestion from a Stack Exchange/Overflow post: How can I do multiple substitutions using regex in python?
import re
repls = {
'california': 'California',
'cal': 'California',
'ca': 'California',
'florida':'Florida',
'fl':'Florida'
}
def multiple_replace(text):
regex = re.compile("(%s\\b)" % "\\b|".join(map(re.escape, repls.keys())),re.I)
return regex.sub(lambda mo: repls[mo.string[mo.start():mo.end()].lower()], text)
The above code goes in the code block, and the field box would be multiple_replace(!State!).
A couple of notes.
- You will need some kind of mapping between what you want to replace and what you are replacing it with. In this example, a dictionary is being used but other Python data structures could be used as well.
- The posted code works on upper or lower case, but the dictionary keys need to be lowercase or you will get a Key Error potentially.