Fastest way to insert these dashes in python string?

前端 未结 8 1485
失恋的感觉
失恋的感觉 2021-02-13 16:34

So I know Python strings are immutable, but I have a string:

c[\'date\'] = \"20110104\"

Which I would like to convert to

c[\'da         


        
8条回答
  •  生来不讨喜
    2021-02-13 17:06

    I'm not usually the guy saying "use regex," but this is a good use-case for it:

    import re    
    c['date']=re.sub(r'.*(\w{4})(\w{2})(\w{2}).*',r"\1-\2-\3",c['date'])
    

提交回复
热议问题