<?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: Calculating Ranges of Non-Consecutive List in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1226323#M65962</link>
    <description>&lt;P&gt;Here is a very inelegant way to do it - add this after your code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;fixed_range_values = ', '.join([r if r.split('-')[0] != r.split('-')[1] else r.split('-')[0] for r in range_values.replace(' ','').split(',')])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Oct 2022 19:01:40 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2022-10-27T19:01:40Z</dc:date>
    <item>
      <title>Calculating Ranges of Non-Consecutive List</title>
      <link>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1226224#M65959</link>
      <description>&lt;P&gt;I have a script that needs to calculate the location numbers within a page and provide the ranges in a formatted list that will be used to fill out a text field to be used with dynamic text. There are often locations missing, so the list won't be consecutive. Right now I have the code below which accomplishes that, but if there is a single non consecutive location it lists it as a range itself i.e. 5-5. Is there a way to edit the script to prevent this?&lt;/P&gt;&lt;P&gt;loc_numbers = [row[0] for row in arcpy.da.SearchCursor(join_lyr, "Map_ID")]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ranges = sum((list(t) for t in zip(loc_numbers, loc_numbers[1:]) if t[0]+1 != t[1]), [])&lt;BR /&gt;iranges = iter(loc_numbers[0:1] + ranges + loc_numbers[-1:])&lt;BR /&gt;range_values = ', '.join([str(n) + '-' + str(next(iranges)) for n in iranges])&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 16:27:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1226224#M65959</guid>
      <dc:creator>MAmbrosini</dc:creator>
      <dc:date>2022-10-27T16:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Ranges of Non-Consecutive List</title>
      <link>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1226323#M65962</link>
      <description>&lt;P&gt;Here is a very inelegant way to do it - add this after your code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;fixed_range_values = ', '.join([r if r.split('-')[0] != r.split('-')[1] else r.split('-')[0] for r in range_values.replace(' ','').split(',')])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 19:01:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1226323#M65962</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-10-27T19:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Ranges of Non-Consecutive List</title>
      <link>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1228369#M66016</link>
      <description>&lt;P&gt;That worked, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 15:39:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-ranges-of-non-consecutive-list/m-p/1228369#M66016</guid>
      <dc:creator>MAmbrosini</dc:creator>
      <dc:date>2022-11-03T15:39:27Z</dc:date>
    </item>
  </channel>
</rss>

