我试图解决这个问题,Python的字符串操作:我有一些符号:没有比较
list =["RBS-UK", "GOOG-US"]
现在我要改造“英国”到“国标”的所有区域发生。我可以很容易地做到这一点:
new_list =[]
for symbol in list :
temp_list=symbol.split("-")
if temp_list[1]=="UK":
temp_list[1]="GB"
new_list.append("-".join(temp_list))
但我可以做这个没有平等的比较吗?
我要找的线沿线的东西:
some_dict={}
new_list =[]
for symbol in list :
temp_list=symbol.split("-")
temp_list[1]=some_dict(temp_list[1]) # So this dict returns GB if its UK else returns same value as it is
new_list.append("-".join(temp_list))
是否有可能做到这一点,还是有什么其他的解决方案?
一旦更换次数增加,这将失控。 – 2013-03-21 15:51:17
是的,对!我认为你的解决方案是最棒的! :) – 2013-03-21 16:10:14