Movatterモバイル変換
[0]ホーム
[Python-Dev] partition() (was: Remove str.find in 3.0?)
skip@pobox.comskip at pobox.com
Tue Aug 30 19:29:04 CEST 2005
Antoine> By the way, re.partition() is *really* useful compared to Antoine> re.split() because with the latter you don't which string Antoine> precisely matched the pattern (it isn't an issue with Antoine> str.split() since matching is exact).Just group your re: >>> import re >>> >>> re.split("ab", "abracadabra") ['', 'racad', 'ra'] >>> re.split("(ab)", "abracadabra") ['', 'ab', 'racad', 'ab', 'ra']and you get it in the return value. In fact, re.split with a grouped re isvery much like Raymond's str.partition method without the guarantee ofreturning a three-element list.Skip
More information about the Python-Devmailing list
[8]ページ先頭