<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Splitting string at &amp;quot;,&amp;quot; multiple addresses in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757297#M58433</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got table field from the county and I just want to&amp;nbsp;extract city from the addresses provided, I don't have any python background.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sample table field situs_addr:&lt;/P&gt;&lt;P&gt;123 street name, city state zip&lt;/P&gt;&lt;P&gt;45 street and street, city state zip&lt;/P&gt;&lt;P&gt;1000 street blvd, city name state zip&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I successfully got the address number with street name separated using "split"&lt;/P&gt;&lt;PRE class="" style="color: #000000; background: #f5f2f0; border: 0px; margin: 0.5em 0px; padding: 1em 1em 1em 3.8em;"&gt;&lt;CODE style="border: 0px; font-weight: inherit;"&gt;!&lt;SPAN&gt;s&lt;/SPAN&gt;&lt;SPAN&gt;itus_addr&lt;/SPAN&gt;!&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;"&gt;','&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I'm having a hard time figuring out how to extract just the city, since the length of each addresses are different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Jul 2020 18:30:28 GMT</pubDate>
    <dc:creator>LABenitez</dc:creator>
    <dc:date>2020-07-21T18:30:28Z</dc:date>
    <item>
      <title>Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757297#M58433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got table field from the county and I just want to&amp;nbsp;extract city from the addresses provided, I don't have any python background.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sample table field situs_addr:&lt;/P&gt;&lt;P&gt;123 street name, city state zip&lt;/P&gt;&lt;P&gt;45 street and street, city state zip&lt;/P&gt;&lt;P&gt;1000 street blvd, city name state zip&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I successfully got the address number with street name separated using "split"&lt;/P&gt;&lt;PRE class="" style="color: #000000; background: #f5f2f0; border: 0px; margin: 0.5em 0px; padding: 1em 1em 1em 3.8em;"&gt;&lt;CODE style="border: 0px; font-weight: inherit;"&gt;!&lt;SPAN&gt;s&lt;/SPAN&gt;&lt;SPAN&gt;itus_addr&lt;/SPAN&gt;!&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;"&gt;','&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I'm having a hard time figuring out how to extract just the city, since the length of each addresses are different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 18:30:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757297#M58433</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T18:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757298#M58434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Lets say you have a variable called address&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;address = '123 street name, city state zip'&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You are correctly splitting the string on the comma. When you do that, you get this&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;
['123 street name', 'city state zip']&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This gives you two items in a list. You want to grab the second item (index 1), and split again... but this time splitting on&amp;nbsp;&lt;STRONG&gt;spaces&lt;/STRONG&gt;. You will then grab the&amp;nbsp;&lt;STRONG&gt;city&lt;/STRONG&gt; on index 0 (state = index 1, zip = index 2).&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;address.split(', ')[1].split(' ')[0]&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The result is&amp;nbsp;the city&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:06:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757298#M58434</guid>
      <dc:creator>DonShawEsri</dc:creator>
      <dc:date>2021-12-12T08:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757299#M58435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;AS the city could be more than 1 word I might suggest splitting by a space, then takin the last but 2 entries:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!situs_addr!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;','&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:06:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757299#M58435</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-12-12T08:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757300#M58436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Situs_Addr.split(',')[1].split(' ')[0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/500938_Untitled.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It didn't work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 19:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757300#M58436</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T19:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757301#M58437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Same, it didn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/500951_Untitled.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 19:40:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757301#M58437</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T19:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757302#M58438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;!Situs_Addr!.split(',')[1].split(' ')[0]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 19:41:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757302#M58438</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T19:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757303#M58439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you 'Check the Geoprocessing results window' for more details?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 19:49:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757303#M58439</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-07-21T19:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757304#M58440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/500953_Untitled.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 20:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757304#M58440</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T20:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757305#M58441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are any of the records blank or missing the ","?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 20:25:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757305#M58441</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2020-07-21T20:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757306#M58442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, some rows are blank.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 20:52:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757306#M58442</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T20:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757307#M58443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;pre-logic window (python):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def func(string):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; #could make this better but does the job probably&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(string) &amp;gt; 0:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = (" ".join(((a.split(',')[1]).split(" "))[:-2]))[1:]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = ""&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; return result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;code window below pre-logic window:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;func(!situs_addr!)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 21:10:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757307#M58443</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-07-21T21:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757308#M58444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;(" ".join(( !Situs_Addr! .split(',')[1]).split(" "))[:-9])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just&amp;nbsp;selected the one with addresses and this code works!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 22:01:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757308#M58444</guid>
      <dc:creator>LABenitez</dc:creator>
      <dc:date>2020-07-21T22:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757309#M58445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The OP didn't state (no pun intended) whether State is name or postal abbreviation.&amp;nbsp; It is likely the latter, but if the former, this approach will fail on several states.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 23:08:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757309#M58445</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-07-21T23:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string at "," multiple addresses</title>
      <link>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757310#M58446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course! I even assured myself that all states had one word names.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 23:26:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-string-at-quot-quot-multiple-addresses/m-p/757310#M58446</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-07-21T23:26:14Z</dc:date>
    </item>
  </channel>
</rss>

