The following is a function that I wrote to display page numbers as they appear in books.If you enter the list [1,2,3,6,7,10], for example, it would return:1-3,6-7,10This seemed like a nice example of how the dictionary data type can be used in Python.Is there is an even more code-efficient way to do this?def formatpagelist (numberlist):    tempdic={}    returnstring=''    for number in numberlist:        if number-1 in tempdic.keys():            tempdic[number-1]=number        elif number-1 in tempdic.values():            for key in tempdic.keys():                if number-1==tempdic[key]: foundkey=key            tempdic[foundkey]=number        else:            tempdic[number]=0    keylist=list(tempdic.keys())    keylist.sort()    for key in keylist:        if tempdic[key]>0:            returnstring+=(str(key)+'-'+str(tempdic[key])+',')        else: returnstring+=str(key)+','    return returnstring
Grouping consecutive numbers into ranges in Python 3.2
python;clustering;interval