Mass string replace in python?

前端 未结 13 2121
我寻月下人不归
我寻月下人不归 2020-11-28 20:14

Say I have a string that looks like this:

str = \"The &yquick &cbrown &bfox &Yjumps over the &ulazy dog\"

You\'ll notic

相关标签:
13条回答
  • 2020-11-28 21:16
    >>> a=[]
    >>> str = "The &yquick &cbrown &bfox &Yjumps over the &ulazy dog"
    >>> d={"&y":"\033[0;30m",                                                              
    ... "&c":"\033[0;31m",                                                                 
    ... "&b":"\033[0;32m",                                                                 
    ... "&Y":"\033[0;33m",                                                                 
    ... "&u":"\033[0;34m"}     
    >>> for item in str.split():
    ...  if item[:2] in d:
    ...    a.append(d[item[:2]]+item[2:])
    ...  else: a.append(item)
    >>> print ' '.join(a)
    
    0 讨论(0)
提交回复
热议问题