def uid_sequence(uidlist):
 def getrange(start, end):
  if (start == end):
   return str(start)
  return ('%s:%s' % (start, end))
 if (not len(uidlist)):
  return ''
 (start, end) = (None, None)
 retval = []
 sorted_uids = sorted(map(int, uidlist))
 for item in iter(sorted_uids):
  item = int(item)
  if (start == None):
   (start, end) = (item, item)
  elif (item == (end + 1)):
   end = item
  else:
   retval.append(getrange(start, end))
   (start, end) = (item, item)
 retval.append(getrange(start, end))
 return ','.join(retval)

def uid_sequence ( uidlist ) : def getrange ( start , end ) : if ( start == end ) : return str ( start ) return ( '%s:%s' % ( start , end ) ) if ( not len ( uidlist ) ) : return '' ( start , end ) = ( None , None ) retval = [ ] sorted_uids = sorted ( map ( int , uidlist ) ) for item in iter ( sorted_uids ) : item = int ( item ) if ( start == None ) : ( start , end ) = ( item , item ) elif ( item == ( end + 1 ) ) : end = item else : retval . append ( getrange ( start , end ) ) ( start , end ) = ( item , item ) retval . append ( getrange ( start , end ) ) return ',' . join ( retval )
collapse uid lists into shorter sequence sets [1 .