<?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 Re: Labeling: Extract specific letters from string in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387933#M69979</link>
    <description>&lt;P&gt;verbose so you can follow&lt;/P&gt;&lt;P&gt;python parser,&lt;/P&gt;&lt;P&gt;`a` is your field as an example&lt;/P&gt;&lt;P&gt;code block&lt;/P&gt;&lt;LI-CODE lang="python"&gt;a = ["South Sweden", "North Sweden", "Sweden"]

def sp(fld):
    if " " in fld:
        spl = fld.split(" ")
        return spl[0][0] + spl[1][0]
    else:
        return fld[0]
        

[sp(i) for i in a]
['SS', 'NS', 'S']&lt;/LI-CODE&gt;&lt;P&gt;calculator expression&lt;/P&gt;&lt;P&gt;sp(!trakt!)&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 09:59:27 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2024-02-28T09:59:27Z</dc:date>
    <item>
      <title>Labeling: Extract specific letters from string</title>
      <link>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387931#M69978</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I could really use some help with a function. I have no experience with phyton and this seems like it could be fairly difficult.&lt;/P&gt;&lt;P&gt;I am trying to label my features. I have a field [&lt;STRONG&gt;trakt&lt;/STRONG&gt;] from which i would like to extract the first letter, and if there is a space, I would also want to extract the first letter after that space.&lt;/P&gt;&lt;P&gt;The field [&lt;STRONG&gt;trakt&lt;/STRONG&gt;] has names in it, for example it could be "&lt;EM&gt;South Sweden&lt;/EM&gt;", "&lt;EM&gt;North Sweden&lt;/EM&gt;" and "&lt;EM&gt;Sweden&lt;/EM&gt;". If the name is "&lt;EM&gt;North Sweden&lt;/EM&gt;" I would like the script to return "&lt;EM&gt;NS&lt;/EM&gt;", but if the name is "&lt;EM&gt;Sweden&lt;/EM&gt;", the script should return only "&lt;EM&gt;S&lt;/EM&gt;". But in reality I have about 50 different names I would like to do this with (edited).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this problem possible to solve?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 12:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387931#M69978</guid>
      <dc:creator>Frida_questions</dc:creator>
      <dc:date>2024-02-28T12:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling: Extract specific letters from string</title>
      <link>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387933#M69979</link>
      <description>&lt;P&gt;verbose so you can follow&lt;/P&gt;&lt;P&gt;python parser,&lt;/P&gt;&lt;P&gt;`a` is your field as an example&lt;/P&gt;&lt;P&gt;code block&lt;/P&gt;&lt;LI-CODE lang="python"&gt;a = ["South Sweden", "North Sweden", "Sweden"]

def sp(fld):
    if " " in fld:
        spl = fld.split(" ")
        return spl[0][0] + spl[1][0]
    else:
        return fld[0]
        

[sp(i) for i in a]
['SS', 'NS', 'S']&lt;/LI-CODE&gt;&lt;P&gt;calculator expression&lt;/P&gt;&lt;P&gt;sp(!trakt!)&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 09:59:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387933#M69979</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-02-28T09:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling: Extract specific letters from string</title>
      <link>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387968#M69980</link>
      <description>&lt;P&gt;Oh thank you! But if I have 50 names rather than just 3, is there a way to do this generally, or do I have to specify all 50 ?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 12:07:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387968#M69980</guid>
      <dc:creator>Frida_questions</dc:creator>
      <dc:date>2024-02-28T12:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling: Extract specific letters from string</title>
      <link>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387974#M69981</link>
      <description>&lt;P&gt;It will do it for all.&amp;nbsp; This is a field calculator function&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 12:34:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-extract-specific-letters-from-string/m-p/1387974#M69981</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-02-28T12:34:05Z</dc:date>
    </item>
  </channel>
</rss>

