本文主要是介绍将城市名称替换成简写,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
图片左边是城市全称,右边是城市简写。
现在有一句话“this is Republic of Korea,that is United States of America”,要将其中的城市全称替换成城市简写。
#"Republic of Korea"替换成 South Korea
s="this is Republic of Korea,that is United States of America"
dict={"Republic of Korea": "South Korea", "United States of America": "United States", "United Kingdom of Great Britain and Northern Ireland": "United Kingdom", "China, Hong Kong Special Administrative Region": "Hong Kong"}
for key in dict:s=s.replace(key,dict[key])print(s)
这篇关于将城市名称替换成简写的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!