Zipping together unicode strings in Python

后端 未结 4 1746
感动是毒
感动是毒 2021-01-24 18:18

I have the string:

a = \"ÀÁÂÃÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜ\" b = \"àáâãäèéçêëìíîïòóôõöùúûüÿ\"

and I want to create the string

\"ÀàÁáÂâ...\"         


        
4条回答
  •  借酒劲吻你
    2021-01-24 18:58

    You have to join them up after you zip them, and also you need to define them as unicode strings:

    >>>import itertools
    >>>a = u"ÀÁÂÃÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜ"
    >>>b = u"àáâãäèéçêëìíîïòóôõöùúûüÿ"
    >>>zipped = itertools.izip_longest(a,b, fillvalue="")
    >>>print "".join(["".join(x) for x in zipped])
    
    ÀàÁáÂâÃãÈäÉèÊéËçÌêÍëÎìÏíÒîÓïÔòÕóÖôÙõÚöÛùÜúûüÿ
    
    >>>zipped = itertools.izip_longest(a,b, fillvalue="")
    >>>print "".join(map("".join, zipped))
    
    ÀàÁáÂâÃãÈäÉèÊéËçÌêÍëÎìÏíÒîÓïÔòÕóÖôÙõÚöÛùÜúûüÿ
    

提交回复
热议问题