{"id":11859,"date":"2025-11-30T00:10:05","date_gmt":"2025-11-30T05:10:05","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=11859"},"modified":"2025-11-30T00:10:05","modified_gmt":"2025-11-30T05:10:05","slug":"python-partition-and-rpartition","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=11859","title":{"rendered":"Python: Partition and RPartition"},"content":{"rendered":"<p>Found a neat pair of methods that were added in Python 2.5 &#8212; it&#8217;s like split\/index except it handles breaking the string into two elements for you. A tuple is returned with the part before the separator, the separator, and the part\u00a0<em>after<\/em> the separator. If the separator is not found, element 0 and 1 are empty strings.<\/p>\n<p>&nbsp;<\/p>\n<p>C:\\Users\\lisa&gt; python<br \/>\nPython 3.13.3<br \/>\nType &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br \/>\n&gt;&gt;&gt; test = &#8220;This is a string | with pipe characters as | delimiters in the string&#8221;<br \/>\n&gt;&gt;&gt; print(test.rpartition(&#8220;|&#8221;)[0])<br \/>\nThis is a string | with pipe characters as<br \/>\n&gt;&gt;&gt; print(test.partition(&#8220;|&#8221;)[0])<br \/>\nThis is a string<br \/>\n&gt;&gt;&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Found a neat pair of methods that were added in Python 2.5 &#8212; it&#8217;s like split\/index except it handles breaking the string into two elements for you. A tuple is returned with the part before the separator, the separator, and the part\u00a0after the separator. If the separator is not found, element 0 and 1 are &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1945],"tags":[664],"class_list":["post-11859","post","type-post","status-publish","format-standard","hentry","category-python","tag-python"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11859"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11859\/revisions"}],"predecessor-version":[{"id":11860,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11859\/revisions\/11860"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}