如何在 Python 2 中折叠字符串? [英] How do I case fold a string in Python 2?

查看:42
本文介绍了如何在 Python 2 中折叠字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 3.3 将 casefold 方法添加到 str 类型,但在 2.x 中我没有任何东西.解决此问题的最佳方法是什么?

解决方案

查看 py2casefold.

<预><代码>>>>从 py2casefold 导入 casefold>>>打印 casefold(u"tschüß")tschüss>>>casefold(u"ΣίσυφοςfiÆ") == casefold(u"ΣΊΣΥΦΟσFIæ") == u"σίσυφοσfiæ"真的

Python 3.3 adds the casefold method to the str type, but in 2.x I don't have anything. What's the best way to work around this?

解决方案

Check out py2casefold.

>>> from py2casefold import casefold
>>> print casefold(u"tschüß")
tschüss
>>> casefold(u"ΣίσυφοςfiÆ") == casefold(u"ΣΊΣΥΦΟσFIæ") == u"σίσυφοσfiæ"
True

这篇关于如何在 Python 2 中折叠字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆